css selector(選擇子)格式

來源:互聯網
上載者:User

 common selector(通用選擇子)

    element/type selector:      p,h1,a{color:#444; padding:3px;}
    Descendant selectors(後代選擇子)   li a{color:#444; } 此樣式只對 li下的 a 有效。這兩種表示方法一般是對整個頁面中的元素設定樣式。
    對於只設定部分樣式的情況用class和id,class可以被任意多的元素使用,而id一般只針對某一個元素,整個頁面唯一。
   ID selector: 以#號開始    #ID_Name{color:#444}
   class selector: 以.號開始   .Class_name{color:#444}

可以組合 type Descendant id/class selector,    #ID_name li{color:#444}   .class_name li{color:#444}, #ID_name .class_name{color:#444}. 這種寫法類似物件導向中對象的引用。

除了靜態使用 css樣式外,還可以根據對象的狀態來應用不同的樣式,稱為 pseudo-class
/* makes all visited links green */
a:visited {color:green;}
/* makes links red when hovered or activated */
a:hover, a:active {color:red;}

universal selector (全域選擇子)

     *{color:#44}應用於文檔中所有的element

進階選擇子
目前 ie6並不支援,你可以對element的某個屬性設定css style,甚至根據屬性值來設定樣式。

 

http://css.maxdesign.com.au/floatutorial/index.htm

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.