在CSS中指定多个属性选择器 [英] Specify multiple attribute selectors in CSS
问题描述
执行类似操作的语法是什么
What is the syntax for doing something like:
input[name="Sex" AND value="M"]
基本上,我想选择具有属性name="Sex"
以及属性value="M"
的input
元素:
Basically, I want to select the input
element that has the attribute name="Sex"
as well as the attribute value="M"
:
<input type="radio" name="Sex" value="M" />
不应选择以下元素,例如
Elements such as the following should not be selected:
<input type="radio" name="Sex" value="F" />
推荐答案
简单的input[name=Sex][value=M]
会很好.实际上,它在标准文档中得到了很好的描述:>
Simple input[name=Sex][value=M]
would do pretty nice. And it's actually well-described in the standard doc:
可以使用多个属性选择器来引用多个 元素的属性,甚至是同一属性的几次.
Multiple attribute selectors can be used to refer to several attributes of an element, or even several times to the same attribute.
在此,选择器匹配其"hello"属性的所有SPAN元素 的值正好是克利夫兰",并且其再见"属性具有 确切的值为哥伦布":
Here, the selector matches all SPAN elements whose "hello" attribute has exactly the value "Cleveland" and whose "goodbye" attribute has exactly the value "Columbus":
span[hello="Cleveland"][goodbye="Columbus"] { color: blue; }
请注意,仅当该值不是有效的标识符时,才需要在属性值周围使用引号.
As a side note, using quotation marks around an attribute value is required only if this value is not a valid identifier.
这篇关于在CSS中指定多个属性选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!