CSS [attribute=value] 选择器
实例
为 target="_blank" 的 <a> 元素设置样式:
<!DOCTYPE html><html><head><style>a[target=_blank] {background-color: yellow;}</style></head><body><p>下面带有target="_blank"的链接具有黄色的背景:</p><a href="https://cankaoshouce.com">cankaoshouce.com</a><a href="http://www.disney.com" target="_blank">disney.com</a><a href="http://www.wikipedia.org" target="_top">wikipedia.org</a></body></html>
浏览器支持
表格中的数字注明了完全支持该属性的首个浏览器版本。
| 选择器 | |||||
|---|---|---|---|---|---|
| [attribute=value] | 4.0 | 7.0 | 2.0 | 3.1 | 9.6 |
注释:对于 IE8 及更早版本的浏览器中的 element>element,必须声明 <!DOCTYPE>。
定义和用法
[attribute=value] 选择器用于选取带有指定属性和值的元素。
相关页面
CSS 教程:CSS 属性选择器