是否有可能选择多个孩子过去的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;
}
是否有可能选择多个孩子过去的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;
}
我不知道哪个浏览器支持,但你可以通过一个公式:第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>