CSS how elements set background for transparent instance analysis (graphic)

Source: Internet
Author: User
To set the background for an element to be transparent, in Chrome, Firefox, and Opera:

Background-color:rgba (0, 0, 0, 0.4);

The last parameter in RGBA 0.4 is the desired transparency, which ranges between 0~1.

This is usually the case in IE:

Background-color:rgb (0, 0, 0); Filter:alpha (opacity=40);

Opacity represents transparency, and its value range is between 0~100

So how is it compatible with each browser? Just write them together.

Because IE does not support RGBA, it is ignored. Other browsers are generally ignored for what they don't support.

Here's an example:

HTML Code:

<body><p class= "non-transparent" >aaaaa</p></body><p class= "Transparent" ><p class = "box" >box</p></p>

CSS Code:

. non-transparent:hover {background-color:yellow;}. Transparent {position:absolute;top:0;left:0;text-align:center;width:100%;height:100%;filter:alpha (opacity=40); Background-color:rgb (0, 0, 0); Background-color:rgba (0, 0, 0, 0.4);}. box {background-color:yellow;width:50%;height:50%;p osition:relative;left:5%;top:10%;}

Display effect:

Chrome:


Firefox


Opera


IE8:


In addition, you can do this in Chrome, Firefox, and Opera:

opacity:0.4;

However, the transparency of all child elements is also set to the same value, such as:

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.