css 屬性選取器筆記

來源:互聯網
上載者:User

標籤:margin   eve   erro   letter   intro   block   header   tle   ror   

1、基本選取器:

 

eg:

*{margin:0;padding:0}p{color:black}.content{background:red;}#intro{padding-left:2em;}

 

2、多元素組合選取器

 

 

div p { color:#f00; }#nav li { display:inline; }#nav a { font-weight:bold; }div > strong { color:#f00; }h2 + p { color:#f00; }

 

三、CSS 2.1 屬性選取器

eg:

p[title] { color:#f00; }div[class=error] { color:#f00; }td[headers~=col1] { color:#f00; }p[lang|=en] { color:#f00; }blockquote[class=quote][cite] { color:#f00; }

四、CSS 2.1中的偽類

eg

p:first-child { font-style:italic; }input[type=text]:focus { color:#000; background:#ffe; }input[type=text]:focus:hover { background:#fff; }q:lang(sv) { quotes: "\201D" "\201D" "\2019" "\2019"; }

五、 CSS 2.1中的虛擬元素

eg:

p:first-line { font-weight:bold; color;#600; }.preamble:first-letter { font-size:1.5em; font-weight:bold; }.cbb:before { content:""; display:block; height:17px; width:18px; }background:url(top.png) no-repeat 0 0; margin:0 0 0 -18px; }a:link:after { content: " (" attr(href) ") "; }

 

六、CSS 3的同級元素通用選取器

eg:

p ~ ul { background:#ff0; }

 

七、CSS 3 屬性選取器

eg:

div[id^="nav"] { background:#ff0; }

 

八、CSS 3中與使用者介面有關的偽類

 

 

input[type="text"]:disabled { background:#ddd; }

 

九、CSS 3中的結構性偽類

 eg

p:nth-child(3) { color:#f00; }p:nth-child(odd) { color:#f00; }p:nth-child(even) { color:#f00; }p:nth-child(3n+0) { color:#f00; }p:nth-child(3n) { color:#f00; }tr:nth-child(2n+11) { background:#ff0; }tr:nth-last-child(2) { background:#ff0; }p:last-child { background:#ff0; }p:only-child { background:#ff0; }p:empty { background:#ff0; }

 

十、CSS 3的反選偽類

 

十一、CSS 3中的 :target 偽類

 

轉自:http://www.ruanyifeng.com/blog/2009/03/css_selectors.html

 

在寫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.