如何将CSS应用于除某些类的li中的输入之外的所有输入元素

时间:2015-09-09 11:10:56

标签: html css

input.not(li.tagit-new >input) {
  background-color: lightgrey;
}
<ul id="tagAdministrator" style="width: 505px" class="tagit ui-widget ui-widget-content ui-corner-all">
  <li class="tagit-new" style="box-shadow: none;">
    <input type="text" class="ui-widget-content ui-autocomplete-input" autocomplete="off">//css should not be applied to this
  </li>
</ul>

<input type="text" class="ui-widget-content ui-autocomplete-input" autocomplete="off"> //css should be applied to this

2 个答案:

答案 0 :(得分:2)

您的:not()伪只能接受simple selectors并需要冒号!

&#13;
&#13;
input {background: grey;}
li.tagit-new input {background: purple;}
&#13;
<ul id="tagAdministrator" style="width: 505px" class="tagit ui-widget ui-widget-content ui-corner-all">
  <li class="tagit-new" style="box-shadow: none;">
    <input type="text" class="ui-widget-content ui-autocomplete-input" autocomplete="off">//css should not be applied to this
  </li>
</ul>

<input type="text" class="ui-widget-content ui-autocomplete-input" autocomplete="off"> //css should be applied to this
&#13;
&#13;
&#13;

答案 1 :(得分:1)

我会做两种不同的风格:

input {
    background-color:lightgrey;
}
li > input {
    background-color:white;
}

或者让#&#34;在&#34;以外 - 输入一个班级。