CSS:屬性選取器

來源:互聯網
上載者:User

標籤:html   css   w3c   

本文介紹css中屬性選取器的基本用法:為具備指定屬性的標籤設定樣式。

代碼整理自w3school:http://www.w3school.com.cn

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta http-equiv="Content-Language" content="zh-cn" /><title>屬性選取器</title><!--對帶有指定屬性的 HTML 元素設定樣式。--><head>  <style>    [title] {color:red}    [type=W3School] {background-color:#afa}    [userDefineType~=W3School] {background-color:#aaf}    [userDefineType02|=W3School] {background-color:#aaf}    div[userDefineType03=W3School] {background-color:#faa}  </style></head><body>  <h3>(一)所有帶有title屬性的html標籤將顯示為紅色。</h3>  <h4 title="title01">帶有title屬性的h4.</h4>  <a title="title02" href="http://www.baidu.com">帶有title屬性的超連結.</a>  <h4>沒有title屬性的h4.</h4>  <a href="http://www.baidu.com">沒有title屬性的超連結.</a>  <hr/>  <h3>(二)所有type=W3School的html標籤的背景色將顯示為淡綠色。</h3>  <p type="W3School">這是type=W3School的</p>  <p type="otherType">有type屬性,但是值不為W3School.</p>  <p>沒有有type屬性的</p>  <hr/>  <h3>(三)所有userDefineType屬性包含W3School的html標籤的背景色將顯示為淡藍色,適用於由空格分隔的屬性值。(“模糊搜尋”)</h3>  <p userDefineType="Hello W3School">userDefineType="Hello W3School"</p>  <p userDefineType="W3School Hello">userDefineType="W3School Hello"</p>  <p userDefineType="W3SchoolAAA">userDefineType="W3SchoolAAA"<p>  <p userDefineType="otherType">userDefineType="otherType"</p>  <hr/>  <h3>(四)同上,適用於由連字號分隔的屬性值。注意:屬性值必須以style中指定的“模糊搜尋”的屬性值開始!</h3>  <p userDefineType02="W3School-AA">userDefineType02="W3School-AA"</p>  <p userDefineType02="AA-W3School">userDefineType02="AA-W3School"</p>  <p userDefineType02="W3School Good">userDefineType02="W3School Good"<p>  <p userDefineType02="otherType">userDefineType02="otherType"</p>  <hr/>  <h3>(五)指定屬性userDefineType03隻有用在div上才有效</h3>  <div userDefineType03="W3School">    <p>div擁有屬性userDefineType03="W3School"</p>  </div>  <p userDefineType03="W3School">p擁有屬性userDefineType03="W3School"</p></body></html>
:


CSS:屬性選取器

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.