css 属性选择器 - 根据html元素的name属性值选择改元素

WBOY
Release: 2016-06-01 09:53:05
Original
3009 people have browsed it

css属性选择器语法:

<code>[attribute=value] 如:[target=-blank] /*选择所有使用target="-blank"的元素*/
或 
[attribute~=value] 如:[title~=flower]  /*选择标题属性包含单词"flower"的所有元素*/
或
[attribute|=language] 如:[lang|=en] /*选择一个lang属性的起始值="EN"的所有元素*/</code>
Copy after login

 

css属性选择器实例一:

选择所有使用target="_blank"的a元素

<code class="language-html">


<style>
a[target=_blank]
{
background-color:yellow;
}
</style>



<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>

</code>
Copy after login

在线运行

 

css属性选择器实例二:

选择标题属性包含单词"flower"的所有元素

<code class="language-html">


<style>
[title~=flower]
{
border:5px solid yellow;
}
</style>



<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" alt="css 属性选择器 - 根据html元素的name属性值选择改元素" >
<img  src="/images/online_demo/klematis.jpg" title="flowers" alt="css 属性选择器 - 根据html元素的name属性值选择改元素" >
<img  src="/images/online_demo/klematis.jpg" title="landscape" alt="css 属性选择器 - 根据html元素的name属性值选择改元素" >

<p><b>Note:</b> For [<i>attribute</i>~=<i>value</i>] to work in IE8 and earlier, a DOCTYPE must be declared.</p>


</code>
Copy after login

在线运行

 

css属性选择器实例二:

选择一个lang属性的起始值="en"的所有元素

<code class="language-html">


<style>
[lang|=en]
{
background:yellow;
}
</style>



<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>


</code>
Copy after login

在线运行

 

相关阅读:

css选择器

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!