小编pai*_*ige的帖子

css nth-child(1)选择了第二个元素,为什么?

我想要的:了解n-child(n).我的理解是,nth-child(1)将选择每个第一个元素.所以应该选择苹果,水果,香蕉来展示红色.

实际显示:但番茄和芒果也被选中并显示为红色.

码:

a {
    text-decoration: none;
    color: black;
}

:nth-child(1) {
    color: red;
}
Run Code Online (Sandbox Code Playgroud)
<ul>
    <li>apple</li>
    <li>tomato</li>
    <li>
        <a href="#">fruit</a>
        <a href="#">juice</a>
    </li>
</ul>
<div>
    <span>
        <a href="#">banana</a>
        <em>mango</em>
    </span>
</div>
Run Code Online (Sandbox Code Playgroud)

html css css-selectors

2
推荐指数
1
解决办法
472
查看次数

标签 统计

css ×1

css-selectors ×1

html ×1