CSS3 RGBA attributes advanced usage

Source: Internet
Author: User

It seems that the discussion on CSS3 on the Internet is very popular recently. Now let's talk about the advanced usage of the wide range of RGBA attributes in CSS3. The compatibility of this attribute is relatively simple. IE8 supports this attribute, and IE6 and IE7 can also be supported by hack. The RBG attribute in RGBA and CSS2 is similar, but the RGBA attribute has a definition of transparency. The RGBA attribute is interpreted as follows in CSS3:

/* Basic syntax */
Em {color: Rgba (red, green, blue, opacity )}
/* Example */
Em {color: rgba (,)}/* red, opaque */
Em {color: rgba (100%, 0%, 0%, 1)}/* same as above */

In reality, use three ~ The decimal value of 255 is more accurate to define a color than the percentage. The following is the RGB values of several colors. You only need to set 00 ~ Convert the hexadecimal value of FF to decimal.

How to Use RGBA attributes

The strength of RGBA is that the definition of transparency and the color mixing of different layers can present more colors, just like the mixture of pigments. For example, we first set a background image for the page, and then set a color for the content in H1, for example:

H1 {
Color: rgb (0, 0, 0 );
Background-color: rgb (255,255,255 );
}

The effect is as follows:

Here we can see that H1 is not transparent.

But if I didn't set an overall transparency (opacity attribute) for H1, what would happen?

H1 {
Color: rgb (0, 0, 0 );
Background-color: rgb (255,255,255 );
Opacity: 0.5;
}


The effect we can see here is that the entire H1, including the text, shows 50% transparency. However, text transparency affects reading. We can use the RGBA attribute to set the background color of H1 separately.

H1 {
Color: rgb (0, 0, 0 );
Background-color: rgba (255,255,255, 0.5 );
}


We can see that the H1 background is 50% transparent white, but the text in it is still opaque black. Of course, you can only make the text in H1 transparent.

H1 {
Color: rgba (0, 0, 0, 0.5 );
Background-color: rgb (255,255,255 );
}


Only make the text transparent and can be used to create the paper-cut effect.

  • 2 pages in total:
  • Previous Page
  • 1
  • 2
  • Next Page

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.