CSS only changes the background transparency, does not change child element transparency

Source: Internet
Author: User

In general, we can use CSS's Opcity property to change the transparency of an element, but the transparency of the child elements under its element will also be changed, even if the child element is redefined, for example:

HTML code
    1. <div style="opacity:0.4; Background-image:url (...); " >
    2. <div style="opacity:1.0;" >
    3. Display text
    4. </div>
    5. </div>

The transparency of the text element will also be 0.4.

Then think about it, if there is a way to only change the transparency of the background can solve the problem.

Method 1: Using a transparent picture for the background can be achieved, but is there a simpler way to do it?

Method 2: Use Rgba.

For example:

HTML code
    1. <div style="0, 0, 0.4)">
    2. <div>
    3. Display text
    4. </div>
    5. </div>

CSS only changes the background transparency, does not change child element transparency

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.