我试图从后面开始隐藏第n个div元素。 使用:nth-last-child(n)选择器只隐藏div中的最后一个元素而不是div本身。
我尝试了以下内容:
.block:nth-last-child(1){display:none;}
以上没有做任何事。
.block:nth-last-child(1){display:none;}
以上只隐藏了div
.block:nth-last-child(1) {display:none;}

<div class='block'>
<button type="button">a</button>
<button type="button">b</button>
<button type="button">c</button>
</div>
<div class='block'>
<button type="button">a</button>
<button type="button">b</button>
<button type="button">c</button>
</div>
<div class='block'>
<button type="button">a</button>
<button type="button">b</button>
<button type="button">c</button>
</div>
<div class='block'>
<button type="button">a</button>
<button type="button">b</button>
<button type="button">c</button>
</div>
&#13;
答案 0 :(得分:1)
SetWindowsHookEx
答案 1 :(得分:0)
A&#34;父母&#34;元素需要有一个&#34;孩子&#34;
.block:nth-last-child(2) {display:none;}
&#13;
<div class='parent'>
<div class='block'>
<button type="button">a0</button>
<button type="button">b0</button>
<button type="button">c0</button>
</div>
<div class='block'>
<button type="button">a1</button>
<button type="button">b1</button>
<button type="button">c1</button>
</div>
<div class='block'>
<button type="button">a2</button>
<button type="button">b2</button>
<button type="button">c2</button>
</div>
<div class='block'>
<button type="button">a3</button>
<button type="button">b3</button>
<button type="button">c3</button>
</div>
</div>
&#13;
答案 2 :(得分:-1)
您的选择器错误,您需要指定您想要选择按钮。
类似的东西:
.block button:last-child {display:none;}
<div class='block'>
<button type="button">1a</button>
<button type="button">1b</button>
<button type="button">1c</button>
</div>
<div class='block'>
<button type="button">2a</button>
<button type="button">2b</button>
<button type="button">2c</button>
</div>
<div class='block'>
<button type="button">3a</button>
<button type="button">3b</button>
<button type="button">3c</button>
</div>
<div class='block'>
<button type="button">4a</button>
<button type="button">4b</button>
<button type="button">4c</button>
</div>