css选择器来匹配没有属性x的元素 [英] css selector to match an element without attribute x
问题描述
我正在处理一个CSS文件,发现需要样式的文本输入框,但是,我遇到了问题。我需要一个简单的声明,匹配所有这些元素:
I'm working on a CSS file and find the need to style text input boxes, however, I'm running into problems. I need a simple declaration that matches all these elements:
<input />
<input type='text' />
<input type='password' />
...但不匹配这些:
... but doesn't match these ones:
<input type='submit' />
<input type='button' />
<input type='image' />
<input type='file' />
<input type='checkbox' />
<input type='radio' />
<input type='reset' />
这里是我想做的:
input[!type], input[type='text'], input[type='password'] {
/* styles here */
}
在上面的CSS中,注意第一个选择器是 input [!type]
。我的意思是我想选择所有的输入框,其中type属性没有指定(因为它默认为文本,但 input [type ='text']
doesn' t匹配它)。不幸的是,在CSS3规范中没有这样的选择器,我可以找到。
In the above CSS, notice the first selector is input[!type]
. What I mean by this is I want to select all input boxes where the type attribute is not specified (because it defaults to text but input[type='text']
doesn't match it). Unfortunately, there is no such selector in the CSS3 spec that I could find.
有没有人知道一种方法来实现这一点?
Does anyone know of a way to accomplish this?
推荐答案
:不选择器
input:not([type]), input[type='text'], input[type='password'] {
/* style here */
}
这篇关于css选择器来匹配没有属性x的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!