CSS 值等于 A 或 B 的属性选择器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6313711/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 00:45:20  来源:igfitidea点击:

Attribute selector where value equals either A or B?

csscss-selectors

提问by Alex Hope O'Connor

I was wondering if it is possible to specify elements in CSS where an attribute is equal to one of two values, something like this:

我想知道是否可以在 CSS 中指定属性等于两个值之一的元素,如下所示:

input[type=text][type=password]

However this selector does not seem to work (I assume because specifying the same attribute twice is not valid), does anyone know how to do this?

但是这个选择器似乎不起作用(我假设是因为两次指定相同的属性是无效的),有谁知道如何做到这一点?

采纳答案by ngen

Like this? http://jsfiddle.net/m242t/

像这样?http://jsfiddle.net/m242t/

HTML:

HTML:

<form>
Username: <input type="username" name="Username" value="Username" /><br />
Password: <input type="password" name="Password" value="Password" /><br />
<input type="submit" value="Submit" />
</form>

CSS:

CSS:

input[type="username"], input[type="password"] {
    color: blue;
}