我使用以下代码来确保响应div不会溢出:

.responsive * {width:100%}


但是,我有一些子元素要从上述规则中排除它们及其子级。因此,我将规则更新为:

.responsive  * :not(.fixedSize,.fixedSize *){max-width:100%;}


上面的代码似乎排除了所有内容。



div {width:200px;border:1px solid #ff0000;line-height:40px;}
input {width:300px;}
.responsive  * :not(.fixedSize,.fixedSize *){max-width:100%;}

<div class="responsive">
   <input>
   <div class="fixedSize">
      <input>
   <div>
</div>





编辑:

我Alseo尝试过此方法,但仍无法正常工作:

 .responsive  * :not(.fixedSize):not(.fixedSize *){max-width:100%;}

最佳答案

您是否要实现这一目标?就像其他人在评论中提到的那样,:not是单个选择器,因此您只能在其中选择单个ID或类。



.responsive {
  width: 200px;
  border: 1px solid #ff0000;
  line-height: 40px;
}

input {
  width: 300px;
}

.responsive *:not(.fixedSize) {
  max-width:100%;
}

<div class="responsive">
  <input>
  <input>
  <input class ="fixedSize">
</div>

关于css - CSS NOT选择器可排除类及其子级,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47744121/

10-11 21:59
查看更多