相关疑难解决方法(0)

选择最后3个孩子

我知道你可以选择最后的寒意:last-child.现在我需要选择最后3个孩子唯一的问题是孩子的数量不知道所以我不能使用:nth-child,我知道有一些被称为:nth-last-child 但我真的不明白这是如何工作的

<div id="something">

    <a href="images/x.jpg"  ><a/>
    <a href="images/x.jpg"  ><a/>
    <!-- More elements here -->
    <!-- ..... -->
    <!-- I need to select these: -->
    <a href="images/x.jpg"  ><a/>
    <a href="images/x.jpg"  ><a/>
    <a href="images/x.jpg"  ><a/>

</div> 
Run Code Online (Sandbox Code Playgroud)

所以现在我需要这样的东西:

#something a:last-child{
   /* only now it selects the last <a> and the 2 <a>'s that come before*/ 
}
Run Code Online (Sandbox Code Playgroud)

css css-selectors

37
推荐指数
3
解决办法
4万
查看次数

标签 统计

css ×1

css-selectors ×1