CSS之虛擬元素

來源:互聯網
上載者:User

標籤:

1.:first-line

向元素的首行文本添加樣式,不必關心首行是元素節點還是文本節點

<style>body,htm,div,p{    margin:0;    padding:0;    }div{    width:100px;    height:100x;    background-color:#FC9;}p{    height:50px;    text-align:center;    line-height:50px;}div > p:first-child{    background-color:#F90    }div > p:last-child{    background-color:#6CC    }div:first-line{    color:red;        background-color:green;}</style><div>     <p>p1</p>     <p>p2</p> </div>

 

 

<style>body,htm,div,p{    margin:0;    padding:0;    }div{    width:100px;    height:100px;    background-color:#FC9;    }p{    height:50px;    text-align:center;    line-height:50px;}div > p:first-child{    background-color:#F90    }div > p:last-child{    background-color:#6CC    }div:first-line{    color:red;        background-color:green;}</style><div>        This is first line        <p>p1</p>        <p>p2</p> </div>

由於文本超過div的寬度,換行後,只有第一行有效果

 2.:first-letter

向文本的第一個字母添加特殊樣式

<style>div:first-letter{    color:red;   }</style><div>        This is first line        <p>p1</p>        <p>p2</p></div>

 

3.

:before 表示在元素的內容之前新插入內容(多媒體或者純文字)

:after 表示在元素的內容之後新插入內容(多媒體或者純文字)

<style>div:before{    content:url(images/info.png);}    </style><div>        This is first line        <p>p1</p>        <p>p2</p> </div>

 

 

 

<style>div{    width:300px;    height:300px;    background-color:#FC9;        text-align:center;}div:before{    content:url(images/info.png);}    div:hover:after{    content:"This is after";    background-color:green;        width:100px;    height:100px;    display:block;    margin:0 auto;}</style><div>        This is first line        <p>p1</p>        <p>p2</p></div>

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.