显示前3列表项和隐藏与CSS第n个孩子休息(Displaying the first 3 list

2019-06-26 20:43发布

是否有可能选择多个孩子过去的CSS选择一个定义的数字?

我想隐藏过去#3所有列表项:

<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li> //hide this
<li>5</li> //hide this
</ul>

ul li:nth-child(X) {  
          display:none;
        }

Answer 1:

我不知道哪个浏览器支持,但你可以通过一个公式:第n-的类型():

ul li:nth-of-type(1n+4) {display: none;} /* should match your case */

:关于进一步细节http://www.w3schools.com/cssref/sel_nth-of-type.asp

编辑

我改变它(N + 4)(1N + 4),因为第一个版本的作品,但无效。 我用这个在媒体查询隐藏在小屏幕上切下来的物品。


例:

 b:nth-of-type(1n+4){ opacity:.3; } 
 <b>1</b> <b>2</b> <b>3</b> <b>4</b> <b>5</b> 



文章来源: Displaying the first 3 list items and hiding the rest with CSS nth-child