CSS3 background transparent, text opaque

Source: Internet
Author: User

Recently encountered a requirement to display text with a translucent background on the picture, as shown in the following:

After seeing this requirement, the first reaction is to use the opacity in CSS3 to set the transparency of the element.

<! DOCTYPE html>

The effect is as follows:

This seems to satisfy the demand, but not perfect, after setting the opacity, the whole element is translucent, resulting in the text appears blurred, such a solution is not advisable.

In fact, the implementation of transparent CSS method is not only set opacity one way. There are two other kinds:

    • CSS3 Rgba (red, green, blue, alpha), alpha values from 0 to 1, such as Rgba (255,255,255,0.8)
    • IE exclusive filter filter:alpha (OPACITY=X), x value from 0 to 100, such as Filter:alpha (OPACITY=80)

Here I have adopted the method of setting Rgba:

<! DOCTYPE html>

The effect is as follows:

After this setting, the text appears much clearer.

Summary

In fact, to achieve this demand, not only this kind of thinking, you can also use two div in the same position, a semi-transparent background div, a text div, the same can solve the problem, but need to write absolute positioning or negative margin, and appear empty content div, This approach is slightly more complex in some scenarios, as shown in the example below, so there are specific problems to be analyzed in the actual requirements scenario.

CSS3 background transparent, text opaque

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.