代码之家  ›  专栏  ›  技术社区  ›  Suresh Ponnukalai

目标为空类[重复]

css
  •  2
  • Suresh Ponnukalai  · 技术社区  · 8 年前

    我想申请 green background 段落 具有 类别 以及 red 一对一。我已经完成了一半,但仍在与空虚作斗争 类别 class="" :

    p {background:green}
    
    #test p:not([class]) {
      background: red;
      color: #fff;
    }
    <div id="test">
      <p>This should be red</p>
      <p class="abc">This should be green</p>
      <p class="newname">This should be green</p>
      <p class="">This should be red</p>
      <p class="anothername">This should be green</p>
      <p>This should be red</p>
      <p class="">This should be red</p>
    </div>

    Fiddle

    有人知道路吗?

    2 回复  |  直到 8 年前
        1
  •  6
  •   sol    8 年前

    您可以针对 p 有这样一个空类。。。

    p[class=""] {
        ...
    }
    

    body {
      font-weight: 700;
    }
    
    p {
      background: green
    }
    
    #test p:not([class]),
    #test p[class=""] {
      background: red;
      color: #fff;
    }
    <div id="test">
      <p>This should be red</p>
      <p class="abc">This should be green</p>
      <p class="newname">This should be green</p>
      <p class="">This should be red</p>
      <p class="anothername">This should be green</p>
      <p>This should be red</p>
      <p class="">This should be red</p>
    </div>
        2
  •  1
  •   Pedro Bauer    8 年前

    我使用了#test p[class=”],我希望这是您想要的。

    body{
      font-weight:700;
    }
    p{background:green}
    
    #test p:not([class]) {
      background:red;
      color:#fff;
    }
    
    #test p[class=""]{
      background:red;
      color:#fff;
    }