![CSS [attribute] 选择器](https://cdn.div.cn/static/images/31f3ccbf2d1a91d28c1e12077e4fd8ba.png)
表示带有以 attribute 命名的属性的元素。
在线示例
选择所有带有target属性的 <a>元素:
<!DOCTYPE html>
<html>
<title>大卫编程网(div.cn)</title>
<head>
<style>
a[target]
{
background-color:blue;
color:white;
}
</style>
</head>
<body>
<p>带有 target 属性的链接将被填充蓝色背景:</p>
<a href="">div.cn</a>
<a href="https://www.baidu.com" target="_blank">baidu.com</a>
<a href="https://www.pcjson.com" target="_top">pcjson.com</a>
<p><b>注意</b> 为了使[<i> attribute </i>]在IE8及更早版本中运行,必须声明DOCTYPE。</ p>
</body>
</html>测试看看 ‹/›浏览器兼容性
所有主流浏览器都支持 [attribute] 选择器。
浏览器兼容性
IEFirefoxOperaChromeSafari
所有主流浏览器都支持 [attribute]选择器。
Note: [attribute] 在IE8中运行,必须声明 <!DOCTYPE> .
相关文章
CSS 教程: CSS 属性选择器/a>
完整CSS选择器参考手册