html - 对元素进行更改
问题描述
我有两个<i>
元素,我只想对第一个元素进行更改。我怎么能不使用类来做到这一点?
<div class="align">
<h2 class="text-uppercase">Contact Us</h2>
<p><i class="fas fa-envelope"></i>example@gmail.com</p>
<p><i class="fas fa-phone-alt"></i>000000000</p>
</div>
解决方案
有许多 CSS 伪选择器可以解决这个问题。这里有两个简单的:
// select a 2nd child element of .align with an <i> inside
.align :nth-child(2) i {
// rules for the <i> element styling
}
// select the first <p> inside align with an <i> inside
.align p:first-of-type i {
// rules for the <i> element styling
}
您只需要确保用于选择的模式是唯一的,这样其他相似的元素就不会被拾取。
推荐阅读
- java - 在namedParameterJdbcTemplate.batchUpdate(query..)中出现错误,在查询中使用in-clause时
- javascript - What happens to other observables when rxjs.race() has been won?
- regex - 正则表达式在“/”之前返回所有字符,但如果有 2 个“/”,则在此之前返回所有字符
- android - Funtouch OS 中的 Play 服务视觉 API
- android - 对于我在广播接收器中指定的任何条件,我都看不到 toast 消息
- java - Testng && Spring上下文单元测试->测试方法前后执行sql
- ios - 使用 UserDefault 快速存储和检索数组数据
- go - 如何遍历命令行参数并收集标志后剩余的内容?
- python-3.x - Python Dataclass - 从属性名称获取元数据
- selectpdf - SelectPDF - 不使用包含的 CCS 文件进行样式设置