当前位置:主页 > 查看内容

css中使用rgba和opacity设置透明度的区别(附图)

发布时间:2021-08-09 00:00| 位朋友查看

简介:1.使用rgba设置背景色的透明 效果如下: body div id=box 你好啊! /div/bodybody { 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)……

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会同时影响字体的透明度

以上就是两者之间的差别和详细解释啦,希望对大家有所帮助~~


原文链接:https://m.jb51.net/css/571516.html
本站部分内容转载于网络,版权归原作者所有,转载之目的在于传播更多优秀技术内容,如有侵权请联系QQ/微信:153890879删除,谢谢!

推荐图文


随机推荐