表示帶有以 attribute 命名的屬性的元素。
選擇所有帶有target屬性的 <a>元素:
<!DOCTYPE html>
<html>
<title>菜鳥教程(cainiaoplus.com)</title>
<head>
<style>
a[target]
{
background-color:blue;
color:white;
}
</style>
</head>
<body>
<p>帶有 target 屬性的鏈接將被填充藍(lán)色背景:</p>
<a href="//www.jixiangtaizi.com.cn">(cainiaoplus.com)</a>
<a href="//www.baidu.com" target="_blank">baidu.com</a>
<a href="//www.pcjson.com" target="_top">pcjson.com</a>
<p><b>注意</b> 為了使[<i> attribute </i>]在IE8及更早版本中運(yùn)行,必須聲明DOCTYPE。</ p>
</body>
</html>測試看看 ?/?所有主流瀏覽器都支持 [attribute] 選擇器。
IEFirefoxOperaChromeSafari
所有主流瀏覽器都支持 [attribute]選擇器。
Note: [attribute] 在IE8中運(yùn)行,必須聲明 <!DOCTYPE> .
CSS 教程: CSS 屬性選擇器/a>
完整CSS選擇器參考手冊