How can I use CSS to control the background transparency of a webpage?

Source: Internet
Author: User
How can I use CSS to control the background transparency of a webpage? In this article, we use the general idea: to make two layers, one for text and the other for transparent background (using filters ).

Implementation Method in IE:

HTML code:
<Div class = "alpha1">
  <Div class = "AP2">
      <P> the background is red (# ff0000) and the transparency is 20%. </P>
  </Div>
</Div>

CSS code:
. Alpha1 {
    Width: 300px;
    Height: 200px;
    Background-color: # ff0000;
    Filter: alpha (opacity = 30 );
}
. AP2 {
    Position: relative;
}
This can basically be achieved without worrying about positioning and self-adaptation. The biggest problem is that it is only supported by IE.
If it is compatible with ff and OP, how can it be written? First of all, the above method is not feasible, so we can only use the method of overlapping two layers.
Modify the Page Structure and CSS style:
HTML code:
<Div class = "alpha1">
  <Div class = "AP2">
      <P> the background is red (# ff0000) and the transparency is 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 );
}
. Alpha2 {
    Background-color: # ffffff;
    -Moz-opacity: 0.8;
    Opacity: 0.8;
}
. 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.