css表达式:没有两个条件

时间:2014-03-21 01:07:11

标签: html css

我有这种奇怪的情况,我无法工作:不是有两个条件。基本上 我想隐藏容器中的所有div,除了具有特定类的容器。

例如,这是html

<div id="container">

  <div class="show"></div>
  <div class="extra"></div>
  <div class="about"></div>

  <div class="sample1"></div>
  .
  .
  .
  <div class="sampleetc"></div> 
</div>

现在我的css表达式是这样的,但它不起作用

 #container > div:not(.show), #container > div:not(.about){
     display:none;
   }

任何想法为什么它不起作用或好的css表达式,我推测,:不能用于两个条件,或者我猜第一个表达式已隐藏.about

2 个答案:

答案 0 :(得分:3)

我相信你可以像这样链接:not选择器:

div#container > div:not(.show):not(.about)
{
    display: none;
}

它似乎在this fiddle上正常工作。

答案 1 :(得分:1)

这就是你想要的。隐藏容器内的所有内容,但div.show和下一个

   #container > div:not(.show) + div{
     display:none;
   }

DEMO