Realization of background translucent effect with CSS

Source: Internet
Author: User
Tags filter

How to use CSS to achieve background translucent effect? The students who have done the activity page may encounter the effect of having to do the background translucent, our general practice is to use two layers, one for the text, the other for transparent background, because the effect of the transparent filter will affect the contents of the inside. But if you only need to implement it under IE, we have a simpler approach:

HTML code:

<div class="alpha1">
 <div class="ap2">
   <p>背景为红色(#FF0000),透明度20%。</p>
 </div>
</div>

CSS code:

.alpha1{
  width:300px;
  height:200px;
  background-color:#FF0000;
  filter: Alpha(Opacity=30);
}
.ap2{
  position:relative;
}

This basically can be achieved, also do not worry about positioning and adaptive problems, the biggest problem is IE support only.

If you are compatible with FF, op How to write it? First of all, the above method is not good, it can only use two layers of overlapping methods.

Change the page structure and CSS style:

HTML 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 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;
}



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.