【发布时间】:2017-05-23 15:03:53
【问题描述】:
我的论坛上有太多的注销链接。我不想显示第二个和第三个,我只想显示第一个。
class = bbpresslogouturl
我试过了:
.bbpressloginurl:nth-last-of-type(2){display:none;}
.bbpressloginurl:nth-last-of-type(1){display:none;}
但这在使用 css 时不起作用。有没有办法使用 jQuery 选择第 n 个类?
【问题讨论】:
-
$('.bbpresslogouturl').not(':first').hide() -
:nth-last-of-type仅关心元素类型。 CSS 中没有:nth-of-class。您将不得不求助于 Javascript。 -
使用
:nth-child() or .eq()而不是.eq()索引从 0 开始 -
如前所述...使用
nth-childw3schools.com/cssref/sel_nth-child.asp -
根据您的 HTML 结构,可能会有基于 CSS 的解决方案。如果我们不知道 HTML,就不可能说出来。