本文共 1891 字,大约阅读时间需要 6 分钟。
本文翻译自:
This question already has an answer here: 这个问题在这里已有答案:
I'm working on a CSS file and find the need to style text input boxes, however, I'm running into problems. 我正在研究CSS文件并发现需要设置文本输入框的样式,但是,我遇到了问题。 I need a simple declaration that matches all these elements: 我需要一个匹配所有这些元素的简单声明:
... but doesn't match these ones: ......但不符合这些:
Here's what I would like to do: 这就是我想做的事情:
input[!type], input[type='text'], input[type='password'] { /* styles here */}
In the above CSS, notice the first selector is input[!type]
. 在上面的CSS中,注意第一个选择器是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). 我的意思是我想选择未指定type属性的所有输入框(因为它默认为文本但input[type='text']
与它不匹配)。 Unfortunately, there is no such selector in the CSS3 spec that I could find. 不幸的是,我找不到CSS3规范中没有这样的选择器。
Does anyone know of a way to accomplish this? 有谁知道这样做的方法?
参考:
只是想添加到这个,你可以使用selectivizr在oldIE中使用:not selector: ://selectivizr.com/
:not selector :不是选择器
input:not([type]), input[type='text'], input[type='password'] { /* style here */}
in Internet Explorer 9 and higher 在Internet Explorer 9及更高版本中
For a more cross-browser solution you could style all inputs the way you want the non-typed, text, and password then another style the overrides that style for radios, checkboxes, etc. 对于更多跨浏览器的解决方案,您可以按照您希望的方式设置所有输入的样式,非文本和密码,然后另一种样式覆盖无线电,复选框等样式。
input { border:solid 1px red; }input[type=radio], input[type=checkbox], input[type=submit], input[type=reset], input[type=file] { border:none; }
- Or - - 要么 -
could whatever part of your code that is generating the non-typed inputs give them a class like .no-type
or simply not output at all? 你生成非类型输入的代码的任何部分都可以为它们提供类似.no-type
或者根本不输出它们? Additionally this type of selection could be done with jQuery. 此外,这种类型的选择可以使用jQuery完成。
转载地址:http://bzjnb.baihongyu.com/