html - CSS - 在 :not 中使用选择器

标签 html css css-selectors

.formSec .formWrap input[type="text"]:not(.counter input[type="text"]):not(other){
   width:80%;
   text-align:left;
}

我尝试使用 :not 使 formWrap 类中的所有输入框都为 80%,但 .counter 类中包含的输入框除外。

我必须将计数器类保留在父 div 中,它不能应用于输入框,而且我也不想将类应用于排除的输入框,这可能吗?

<div class="formSec">
<div class="formWrap counter">
<input type="text" size="4" maxlength="4" />
</div>
<div class="formWrap">
<input class="other" type="text" size="4" maxlength="4" />
</div>
<div class="formWrap">
<input type="text" size="4" maxlength="4" />
</div>
</div>
</div>

这是我需要保留的 HTML,因此只有第二个输入才是 80%。

最佳答案

CSS :not() negation pseudo-class只接受simple selector作为参数,它不应包含另一个 :not()伪类或任何伪元素。还有 Combinators 是不允许的。这意味着.counter input[type="text"]不是一个有效的论点。

Spec来自 CSS Selectors level 3 :

A simple selector is either a type selector, universal selector, attribute selector, class selector, ID selector, or pseudo-class.

您可以选择.formWrap没有 .counter 的元素类(class) .formWrap:not(.counter)然后定位嵌套的 <input>不包括 .other 的元素类(class) input[type="text"]:not(.other)如下:

<强> Example Here

.formSec .formWrap:not(.counter) input[type="text"]:not(.other) { /*
                  ^----     No spaces here     ----^              */
   width:80%;
   text-align:left;
}

(检查 revisions 中是否有基于旧标记的旧答案)

关于html - CSS - 在 :not 中使用选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25993934/

相关文章:

javascript - jQuery 下拉值根据变量而变化

html - 将屏幕调整为更小时出现页脚

css - 关于 .well 类中 Bootstrap 图像绝对位置的问题

javascript - CSS 不适用于文本区域

html - 使用 CSS 定位文本节点

css - 包含类、子级和相邻同级选择器的 CSS 选择器的等效 XPath 是什么?

html - 包含表格单元格的 polymer 自定义元素?

javascript - 如何让我的导航链接的子列表项显示在它的右侧?

ruby-on-rails - 帮助将两种不同的样式应用于 Ruby on Rails 复数化方法

html - 写 CSS 媒体内容时可以使用 Bootstraps 列吗?