在CSS中指定多个属性选择器 [英] Specify multiple attribute selectors in CSS

查看:490
本文介绍了在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.

JSFiddle演示

这篇关于在CSS中指定多个属性选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆