標籤:under select class letter 狀態 blog orange 部分 cal
首先,關於虛擬元素的文法:
有的時候單冒號也能用,但最好寫雙冒號。
偽類:匹配的是元素(不同狀態或結構的)。
虛擬元素:匹配的是元素中的一部分內容(首字元,首行文本)。
::first-letter
匹配 某元素的 首字元。
例:
<!DOCTYPE html><html><head> <title>test010_虛擬元素選取器_::first-letter</title> <style type="text/css"> p::first-letter{ color:red; } </style></head><body> <p>hello world</p> </body></html>
結果:
::first-line
匹配 某元素的 首行文本。
::selection
匹配 被使用者選取的 部分。
例:
<!DOCTYPE html><html><head> <title>test012_虛擬元素選取器_::selection</title> <style type="text/css"> p::first-line{ color:red; } p::selection{ background-color: orange; color:#e1e1e1; } </style></head> <script type="text/javascript"> </script><body> <p>hello world <br> world is mine </p> </body></html>
結果:
注意:當你修改 ::selection 樣式後,瀏覽器內建的 ::selection會失效。
比如,瀏覽器預設的::selection是藍底白字,而你只是把藍底改成了紅底,那麼,瀏覽器內建的白字設定會失效。
CSS3虛擬元素 ::first-letter ::first-line ::selection