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

來源:互聯網
上載者: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裡字型樣式怎麼設定

相關文章

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.