偽類
1、鏈接偽類:
:link
:visited
2、動態偽類(可應用到任何元素)
:focus
:hover
:active
偽類順序很重要;通常建議:link-visited-focus-hover-active
3、靜態偽類
:first-child(第一個此類元素)
p:first-child { font-weight: bold; } li:first-child { text-transform: uppercase; } <p>there are not </p> <!--起作用--> <p>there are not </p> <!--不起作用--> <p>there are not </p> <!--不起作用--> <p>there are not </p> <!--不起作用--> <div> <p>there are</p> <!--起作用--> <p>there are</p> <ul> <li>key</li> <!--起作用--> <li>key</li> <!--不起作用--> <li>key</li> <!--不起作用--> </ul> <p>do <em>not</em> push</p> </div> <div> <div> <p>other div</p> <!--起作用--> <p>other div</p> <!--不起作用--> <p>other div</p><!--不起作用--> </div> </div>
3、偽類元素選擇器,設置首字母樣式
h1:first-letter { color: red; font-size: 200%; } <h1>first</h1>
設置第一行樣式。
:first-line
所有偽元素都必須出現在該偽元素的最后面。如p:first-letter em就不合法
4、設置之前或之后的元素
h2:before { content: "}}";color: red; } <h2>first</h2>
浙公網安備 33010602011771號