CSS之偽類

來源:互聯網
上載者:User

標籤:

1.:link                     向未被訪問的連結添加樣式:visited                向已被訪問的連結添加樣式:hover                  當滑鼠懸浮在元素上方時,向元素添加樣式:active                 向被啟用的元素添加樣式(被點擊)以上四種偽類應用於超連結時,順序不能改換超連結:
<style>a:link{    color:red;    }a:visited{    color:green;    }a:hover{    color:blue;    }a:active{    color:yellow;    }</style>

<a href="#">pmx-cnblogs</a>

 

 div:
<style>div{    width:100px;    height:100px;    background-color:red;    border:3px solid blue;    overflow:hidden;        transition:width 1s,height 2s,background-color 1s,line-height 2s,font-size 2s;        line-height:100px;    text-align:center;}div:hover{    background-color:green;    width:300px;        height:300px;    line-height:300px;        font-size:2em}div:active{    color:yellow;}</style>

<div>This is div</div>

 

 

 正常狀態:

滑鼠移到div上時的樣子:

滑鼠左鍵按下後得樣子:

 

 2.:first-child p:first-child選擇作為某個元素的第一個子項目的p元素,而不是選擇p元素的第一個子項目
<style>#myDiv > p:first-child{   background-color:#3C6;    }</style><body>    <p>p8</p>    <div id=‘myDiv‘ style=‘width:300px;height:300px;overflow:auto‘>        <p>p1</p>        <p>p2</p>        <p>p3</p>        <div>            <p>p4</p>            <p>p5</p>        </div>    </div>    <p>p6</p>    <p>p7</p></body>

P1作為myDiv的第一個子項目被選中 3.:focus向獲得焦點的元素添加特殊樣式,比如按鈕被點擊後,文字框輸入文本
<style>input:focus{    background-color:yellow;    }</style><input type=‘text‘ value=""/>

 

 

 4. :lang向帶有指定lang屬性的元素添加樣式
<style>:lang(zh){    color:red;    }</style><p lang="zh">p7</p>

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.