/* 选择父元素下的第一个子元素 */
.first-child-example > :first-child {
color: red;
}
/* 示例HTML结构 */
<div class="first-child-example">
<p>我是第一个子元素,会被选中并变为红色。</p>
<p>我是第二个子元素,不会被选中。</p>
</div>
:first-child 是 CSS 中的选择器,用于选择作为其父元素的第一个子元素的元素。.first-child-example > :first-child 会选择 .first-child-example 下的第一个子元素,并将其文本颜色设置为红色。:first-child 只匹配父元素下的第一个子元素,而不一定是特定类型的元素。如果需要选择特定类型(如第一个 <p> 元素),可以使用 :first-of-type。上一篇:css背景颜色渐变从左到右
下一篇:css流光边框
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站