css :after和:before

來源:互聯網
上載者:User

標籤:背景   size   20px   sans   weight   pre   value   name   val   

:before是css中的一種虛擬元素,可用於在某個元素之前插入某些內容。
:after是css中的一種虛擬元素,可用於在某個元素之後插入某些內容。

舉例:

1.結合border寫個對話方塊的樣式。

<style>    .test-div{        position: relative;  /*日常相對定位*/        width:150px;        height: 36px;        border:black 1px solid;        border-radius:5px;        background: rgba(245,245,245,1)    }    .test-div:before,.test-div:after{        content: "";  /*:before和:after必帶技能,重要性為滿5顆星*/        display: block;        position: absolute;  /*日常絕對位置*/        top:8px;        width: 0;        height: 0;        border:6px transparent solid;    }    .test-div:before{        left:-11px;        border-right-color: rgba(245,245,245,1);        z-index:1    }    .test-div:after{        left:-12px;        border-right-color: rgba(0,0,0,1);        z-index: 0    }  </style>  <div class="test-div"></div>

2.作為內容的半透明背景層。

 

  <style>      body{          background: url(ABUIABACGAAg6KijvAUo1PqcwwIwgA84uwU.jpg) no-repeat left top /*這裡加了個圖片背景,用以區分背景的半透明及內容的完全不透明*/      }      .test-div{          position: relative;  /*日常相對定位(重要,下面內容也會介紹)*/          width:300px;          height: 120px;          padding: 20px 10px;          font-weight: bold;      }      .test-div:before{          position: absolute;  /*日常絕對位置(重要,下面內容也會略帶介紹)*/          content: "";  /*:before和:after必帶技能,重要性為滿5顆星*/          top:0;          left: 0;          width: 100%;  /*和內容一樣的寬度*/          height: 100%;  /*和內容一樣的高度*/          background: rgba(255,255,255,.5); /*給定背景白色,透明度50%*/          z-index:-1; /*日常元素堆疊順序(重要,下面內容也會略帶介紹)*/      }  </style>  <!--這裡容獸偷個懶,布局簡單寫寫-->  <body>  <div class="test-div">      <table>          <tr>              <td>Name</td>              <td><input placeholder="your name" /></td>          </tr>           <tr>              <td>Password</td>              <td><input placeholder="your password" /></td>          </tr>           <tr>              <td></td>              <td><input type="button" value="login" /></td>          </tr>      </table>  </div>

 

css :after和:before

聯繫我們

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