我需要使用 css 中的属性选择器来更改不同颜色和图像上的链接,但它不起作用。
我有这个html:
<a href="/manual.pdf">A PDF File</a>
还有这个CSS:
a {
display: block;
height: 25px;
padding-left: 25px;
color:#333;
font: bold 15px Tahoma;
text-decoration: none;
}
a[href='.pdf'] { background: red; }
为什么背景不是红色的?
在 href 后使用 $。这将使属性值匹配字符串的结尾。
a[href$='.pdf'] { /*css*/ }
JSFiddle:http://jsfiddle.net/UG9ud/ http://jsfiddle.net/UG9ud/
E[foo] an E element with a "foo" attribute (CSS 2)
E[foo="bar"] an E element whose "foo" attribute value is exactly equal to "bar" (CSS 2)
E[foo~="bar"] an E element whose "foo" attribute value is a list of whitespace-separated values, one of which is exactly equal to "bar" (CSS 2)
E[foo^="bar"] an E element whose "foo" attribute value begins exactly with the string "bar" (CSS 3)
E[foo$="bar"] an E element whose "foo" attribute value ends exactly with the string "bar" (CSS 3)
E[foo*="bar"] an E element whose "foo" attribute value contains the substring "bar" (CSS 3)
E[foo|="en"] an E element whose "foo" attribute has a hyphen-separated list of values beginning (from the left) with "en" (CSS 2)
source: http://www.w3.org/TR/selectors/ http://www.w3.org/TR/selectors/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)