Home  >  Article  >  Web Front-end  >  Two ways to set transparency in CSS

Two ways to set transparency in CSS

php中世界最好的语言
php中世界最好的语言Original
2018-03-21 16:34:411859browse

This time I will bring you two methods of setting transparency in CSS. What are the precautions for setting transparency in CSS? . Here are practical cases, let’s take a look.

1. Use rgba to set the background color to be transparent

The effect is as follows:

<body>
    <p id="box">
        你好啊!
    </p>
</body>
body {
    background-color:red;
}
#box{
    width:200px;
    height:200px;
    margin:100px auto;
    text-align:center;
    line-height:200px;
    color:white;
    background-color:rgba(182,255,0,.5);
}


2. Use opacity to set the transparency of the background color

#box{
    width:200px;
    height:200px;
    margin:100px auto;
    text-align:center;
    line-height:200px;
    color:white;
    background-color:rgb(182,255,0);
    opacity:0.5;
}

Summary: Through comparison of the effects in 2, we found that opacity will also affect the transparency of the font.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Use CSS3 to achieve barrage effect

What is the difference between href and src, link and @import

The above is the detailed content of Two ways to set transparency in CSS. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn