css属性选择器语法:
[attribute=value] 如:[target=-blank] /*选择所有使用target="-blank"的元素*/
或
[attribute~=value] 如:[title~=flower] /*选择标题属性包含单词"flower"的所有元素*/
或
[attribute|=language] 如:[lang|=en] /*选择一个lang属性的起始值="EN"的所有元素*/
css属性选择器实例一:
选择所有使用target="_blank"的a元素
<!DOCTYPE html>
<html>
<head>
<style>
a[target=_blank]
{
background-color:yellow;
}
</style>
</head>
<body>
<p>The link with target="_blank" gets a yellow background:</p>
<a href="http://www.manongjc.com">manongjc.com</a>
<a href="http://www.disney.com" target="_blank">disney.com</a>
<a href="http://www.wikipedia.org" target="_top">wikipedia.org</a>
<p><b>Note:</b> For [<i>attribute</i>] to work in IE8 and earlier, a DOCTYPE must be declared.</p>
</body>
</html>
在线运行
css属性选择器实例二:
选择标题属性包含单词"flower"的所有元素
<!DOCTYPE html>
<html>
<head>
<style>
[title~=flower]
{
border:5px solid yellow;
}
</style>
</head>
<body>
<p>The image with the title attribute containing the word "flower" gets a yellow border.</p>
<img src="/images/online_demo/klematis.jpg" title="klematis flower" />
<img src="/images/online_demo/klematis.jpg" title="flowers" />
<img src="/images/online_demo/klematis.jpg" title="landscape" />
<p><b>Note:</b> For [<i>attribute</i>~=<i>value</i>] to work in IE8 and earlier, a DOCTYPE must be declared.</p>
</body>
</html>
在线运行
css属性选择器实例二:
选择一个lang属性的起始值="en"的所有元素
<!DOCTYPE html>
<html>
<head>
<style>
[lang|=en]
{
background:yellow;
}
</style>
</head>
<body>
<p lang="en">Hello!</p>
<p lang="en-us">Hi!</p>
<p lang="en-gb">Ello!</p>
<p lang="us">Hi!</p>
<p lang="no">Hei!</p>
<p><b>Note:</b> For [<i>attribute</i>|=<i>value</i>] to work in IE8 and earlier, a DOCTYPE must be declared.</p>
</body>
</html>
在线运行
相关阅读:
css选择器
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!