背景半透明效果

來源:互聯網
上載者:User

<div class="alpha1">
  <div class="ap2">
      <p>背景為紅色(#FF0000),透明度20%。</p>
  </div>
</div>
CSS代碼:

 Example Source Code
.alpha1{
    width:300px;
    height:200px;
    background-color:#FF0000;
    filter: Alpha(Opacity=30);
}
.ap2{
    position:relative;
}
  這樣基本就可以實現啦,也不用擔心定位和自適應問題,最大的問題是僅IE支援。
  如果相容FF、OP怎麼寫呢?首先,上面這種定法是不行的啦,那就只能用兩個層重疊的方法啦。
  改下頁面結構與CSS樣式:

HTML代碼:

 Example Source Code
<div class="alpha1">
  <div class="ap2">
      <p>背景為紅色(#FF0000),透明度20%。</p>
  </div>
  <!--[if IE]><![if !IE]><![endif]--> <div class="alpha2"></div> <!--[if IE]><![endif]><![endif]-->
</div>
CSS代碼:

 Example Source Code
.alpha1,.alpha2{
    width:100%;
    height:auto;
    min-height:250px;/* 必需 */
    _height:250px;/* 必需 */
    overflow:hidden;
    background-color:#FF0000;/* 背景色 */
}
.alpha1{
    filter:alpha(opacity=20); /* IE 透明度20% */
}
.alpha2{
    background-color:#FFFFFF;
    -moz-opacity:0.8; /* Moz + FF 透明度20%*/
    opacity: 0.8; /* 支援CSS3的瀏覽器(FF 1.5也支援)透明度20%*/
}
.ap2{
    position:absolute;
}

聯繫我們

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