CSS3虛擬元素 ::first-letter ::first-line ::selection

來源:互聯網
上載者:User

標籤: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

聯繫我們

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