如何使用CSS隐藏没有类的段落?

时间:2019-02-15 17:38:03

标签: css

我有动态页面,并且包含div和段落,例如:

<div class="oe_view_nocontent">
    <p class="oe_view_nocontent_create">
        Click to add a contact in your contacts directory.
    </p>
    <p>
        Odoo helps you easily track all activities related to
        a customer: discussions, history of business opportunities,
        documents, etc.
    </p>
</div>

我要尝试的是仅显示具有 class =“ oe_view_nocontent” 的那一段,并隐藏另一个没有课程的段落。

我尝试使用以下线程进行整理:

Hide long text except the first two paragraphs

CSS: hide table with no class or id

我尝试过:

p {
    display: none;
}
p.oe_view_noontent {
  display: div;
}

,然后从这里: Can I write a CSS selector selecting elements NOT having a certain class?

我的尝试:

p:not(.class) {
    display: none;
}

但是我什么也没得到。我只想要拥有

  

class =“ oe_view_nocontent_create”

知道我在哪里做错吗?

2 个答案:

答案 0 :(得分:2)

我认为,您正在寻找not:() selector

p:not(.oe_view_nocontent_create) {
    display: none;
}

答案 1 :(得分:1)

发布评论作为答案

p:not(.oe_view_nocontent_create) {
  display:none
}
<div class="oe_view_nocontent">
    <p class="oe_view_nocontent_create">
        Click to add a contact in your contacts directory.
    </p>
    <p>
        Odoo helps you easily track all activities related to
        a customer: discussions, history of business opportunities,
        documents, etc.
    </p>
</div>

codepen-codepen.io/nagasai/pen/rPqXjV

相关问题