css中使用rgba和opacity設置透明度的區別


1.使用rgba設置背景色的透明

效果如下:

<body>
    <div id="box">
        你好啊!
    </div>
</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.使用opacity設置背景色的透明

#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;
}

總結:通過2中效果的比較我們發現opacity會同時影響字體的透明度


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM