我不知道在方括号中附加一个属性名称

时间:2014-08-29 19:26:20

标签: html5 css3

我不知道如何使用它。我用不同的方式尝试过,但没有任何效果。

abbr[title] { border-bottom: 4px dotted green }

1 个答案:

答案 0 :(得分:0)

以下是有关如何完成追加和属性名称的文档: https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors

以下是使用这些属性选择器的演示:http://jsfiddle.net/id_0t/q0g0jako/

<强> HTML:

<div class="hello-example">
    <a href="http://example.com">English:</a>
    <span lang="en-us en-gb en-au en-nz">Hello World!</span>
</div>
<div class="hello-example">
    <a href="#portuguese">Portuguese:</a>
    <span lang="pt">Olá Mundo!</span>
</div>
<div class="hello-example">
    <a href="http://example.cn">Chinese (Simplified):</a>
    <span lang="zh-CN">世界您好!</span>
</div>
<div class="hello-example">
    <a href="http://example.cn">Chinese (Traditional):</a>
    <span lang="zh-TW">世界您好!</span>
</div>

<强> CSS:

/* All spans with a "lang" attribute are bold */
span[lang] {font-weight:bold;}

/* All spans in Portuguese are green */
span[lang="pt"] {color:green;}

/* All spans in US English are blue  */
span[lang~="en-us"] {color: blue;}

/* Any span in Chinese is red, matches simplified (zh-CN) or traditional (zh-TW) */
span[lang|="zh"] {color: red;}

/* All internal links have a gold background */
a[href^="#"] {background-color:gold}

/* All links to urls ending in ".cn" are red */
a[href$=".cn"] {color: red;}

/* All links to with "example" in the url have a grey background */
a[href*="example"] {background-color: #CCCCCC;}