【问题标题】:Select occurence > 1 of css and don't show CSS [duplicate]选择出现> 1的css并且不显示CSS [重复]
【发布时间】:2014-05-24 21:47:27
【问题描述】:

我正在尝试选择此 html 中第一次出现 right_bar 之后的任何出现而不显示它。

<div id="contain">

        <div class="post-18">
            <div id="post_content">
                    <!--content-here-->
            </div>
            <div id="right_bar">
                <!--right_bar-content-->
            </div><!--right_bar-->
            <div id="clear"> </div>
        </div><!--post_class()-->

        <div class="post-18">
            <div id="post_content">
                    <!--content-here-->
            </div>
            <div id="right_bar">
                <!--right_bar-content-->
            </div><!--right_bar-->
            <div id="clear"> </div>
        </div><!--post_class()-->
</div><!--contain-->

我对使用nth selection CSS3 选择器有点生疏,谁能帮忙?

我已尝试以下方法在第一次出现之后删除任何出现的 right_bar(但它没有工作):

#right_bar:not(:first-child){
        display:none;
    }

顺便说一句,这不是重复的。

如果有人可以启发我。谢谢!

【问题讨论】:

  • 它几乎重复的,只是想要隐藏其他 div。

标签: html css


【解决方案1】:

first-child 表示“兄弟姐妹中的第一个”(在同一级别上),因此您需要执行以下操作:

.post-18:not(:first-child) #right_bar{
    display:none;
}

...因为.post-18 处于同一级别。

【讨论】:

    【解决方案2】:

    感谢用户@Mark Resolved 的回答(因为它帮助我制定了一个精确的解决方案来满足我的需求。虽然他的确切语法不起作用,但这对我有用,符合我的需要。谢谢!

    .post:not(:first-child) #right_bar{
        display:none;
    }
    

    【讨论】:

    • 好吧,你发布的代码应该是 .post-18 ...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-13
    • 2013-12-02
    • 2021-02-04
    • 2017-03-26
    • 2016-03-13
    • 1970-01-01
    相关资源
    最近更新 更多