屬性選取器和偽類別選取器的使用方法

來源:互聯網
上載者:User
今天我們來給大家說一下屬性選取器和偽類別選取器的使用方法和相關的聯絡以及區別,下面給大家舉一個小列子。

屬性選取器:

[attr~="value"] 單詞 單詞空格單詞 單詞必須value有效

[attr|="value"] value打頭 或者 value-單詞

注意:

屬性選擇 都是用則很難規則運算式來判別 選擇元素,效率要高一些

偽類別選取器:

:before

:after

:lang(val) val/val-單詞

:nth-child(n) n從1開始算起 odd基數 even偶數

:nth-of-type(n) 選取器匹配屬於父元素的特定類型的第 N 個子項目的每個元素.

<!doctype html><html><head><meta charset="utf-8"><title>無標題文檔</title><link href="css/index.css" rel="stylesheet" type="text/css" /></head><body><!--<p>aaaaaaa</p><p>aaaaaaa</p><p>aaaaaaa</p>---><div>       <p>aaa</p>       <p>aaa</p>       <p>aaa</p>       <p>aaa</p></div></body></html>Css部分:@charset "utf-8";/* CSS Document *//*p:before{       content:"ccc"; } p:lang(en){       border:1px solid #ff0000;  }p:nth-child(even){       background:#F00; }*/p:nth-of-type(3){  /* p標記的父元素 下的 第3個p元素*/       background:#F00; }

相關閱讀:

怎樣隱藏溢出DIV的內容

CSS布局有哪些技巧

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.