gpt4 book ai didi

css - 选择所有 anchor 元素但不选择 :first-child anchor in a class group

转载 作者:太空宇宙 更新时间:2023-11-03 20:46:31 24 4
gpt4 key购买 nike

我必须隐藏所有 anchor 元素,但不能隐藏类组的第一个子元素。在 anchor 开始之前,我放置了 h2 标签。有了这个 h2,我无法获得准确的结果。

View in JS fiddle

HTML

 <div id="main" >
<div class="album">
<h2>title 1 </h2>
<a title="Campus photo" href="images/gallery/campus/0.jpg">
show this
</a>
<a title="Campus photo" href="images/gallery/campus/1.jpg">
not show
</a>
<a title="Campus photo" href="images/gallery/campus/2.jpg">
not show
</a>
<a title="Campus photo" href="images/gallery/campus/3.jpg">
not show
</a>
<a title="Campus photo" href="images/gallery/campus/4.jpg">
not show
</a>
<a title="Campus photo" href="images/gallery/campus/5.jpg">
not show
</a>
<a title="Campus photo" href="images/gallery/campus/6.jpg">
not show
</a>
</div>
<div class="album">
<h2>title 2 </h2>
<a title="Campus photo" href="images/gallery/campus/0.jpg">
show this
</a>
<a title="Campus photo" href="images/gallery/campus/1.jpg">
not show
</a>
<a title="Campus photo" href="images/gallery/campus/2.jpg">
not show
</a>
<a title="Campus photo" href="images/gallery/campus/3.jpg">
not show
</a>
<a title="Campus photo" href="images/gallery/campus/4.jpg">
not show
</a>
<a title="Campus photo" href="images/gallery/campus/5.jpg">
not show
</a>
<a title="Campus photo" href="images/gallery/campus/6.jpg">
not show
</a>
</div>
<div class="album">
<h2>title3 </h2>
<a title="Campus photo" href="images/gallery/campus/0.jpg">
show this
</a>
<a title="Campus photo" href="images/gallery/campus/1.jpg">
not show
</a>
<a title="Campus photo" href="images/gallery/campus/2.jpg">
not show
</a>
<a title="Campus photo" href="images/gallery/campus/3.jpg">
not show
</a>
<a title="Campus photo" href="images/gallery/campus/4.jpg">
not show
</a>
<a title="Campus photo" href="images/gallery/campus/5.jpg">
not show
</a>
<a title="Campus photo" href="images/gallery/campus/6.jpg">
not show
</a>
</div>
</div>

:预期结果:

标题 1显示这个

标题 2显示这个

标题 3显示这个

我按如下方式应用了 css 但没有工作。

.album  a:not(:first-child) {
display:none;
}

当我省略时我得到了正确的结果

<h2>...</h2>

最佳答案

尝试:

.album  a:not(:first-of-type) {
display:none;
}

Updated fiddle here.

关于css - 选择所有 anchor 元素但不选择 :first-child anchor in a class group,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20488294/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com