如何定位具有在CSS中具有任何值的属性的元素? [英] How do I target elements with an attribute that has any value in CSS?
问题描述
我知道我可以定位CSS中具有特定属性的元素,例如:
input [type = text]
{
font-family:Consolas;
}
但是可以定位具有任何值属性的元素
<$ p
p>
a [rel = *]
{
color:red;
}
这应该定位第一个和第三个< a> ; c>
< a href =# =eg >红色文字< / a>
< a href =#>标准文字< / a>
< a href =# =more>红色文字< / a>
我认为这是可能的,因为默认情况下, cursor:pointer
似乎应用于具有其 href
属性的值的任何< a>
标记。 / p>
以下将匹配任何 a
nchor与 rel
属性定义:
a [rel]
{
红色;
}
http://www.w3.org/TR/CSS2/selector.html#pattern-matching
I know that I can target elements which have a specific attribute in CSS, for example:
input[type=text]
{
font-family: Consolas;
}
But is it possible to target elements which have an attribute of any value (except nothing i.e. when the attribute hasn't been added to the element)?
Roughly something like:
a[rel=*]
{
color: red;
}
Which should target the first and third <a>
tags in this HTML:
<a href="#" rel="eg">red text</a>
<a href="#">standard text</a>
<a href="#" rel="more">red text again</a>
I figure it's possible because by default, cursor: pointer
seems to be applied to any <a>
tag which has a value for its href
attribute.
The following will match any a
nchor with a rel
attribute defined:
a[rel]
{
color: red;
}
http://www.w3.org/TR/CSS2/selector.html#pattern-matching
这篇关于如何定位具有在CSS中具有任何值的属性的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!