将display显示为none时出现CSS nth-child问题

时间:2014-08-06 15:00:19

标签: jquery html css

HTML:

<div class="section fp-section fp-table active"></div>
<div class="section fp-section fp-table"></div>
<div class="section fp-section fp-table"></div>
<div class="section fp-section fp-table"></div>
<div class="section fp-section fp-table"></div>

所有五个div都完全相同,只需在选中div时添加“active”挂起。如何去除第四个div?我已经尝试过n-child并且没有显示,但没有运气。

4 个答案:

答案 0 :(得分:3)

试试这个

div:nth-of-type(4){
   display:none;
}

DEMO

答案 1 :(得分:2)

Jquery版本

$('div:nth-child(4)').remove();

DEMO

您也可以隐藏()而不是也适用的remove()。

答案 2 :(得分:0)

以下是实现此目标的另一种方法:

div:nth-last-child(2) {
    display: none;
}

希望它也有帮助!

答案 3 :(得分:0)

nth-child对我很好

div:nth-child(4) {
  display: none;
}

http://codepen.io/anon/pen/hIyDm