在制作一些半透明的小图标的时候,有两种方法使不透明的图标变半透明,下面看一下两者的区别
RGBA()
在RGBA模式中,前三个参数是控制颜色,最后一个参数控制透明度
最后一个参数在0—1之间,可以是小数。当它为0时代表完全透明,为1代表不透明
opcity
opcity也可以调整透明度,取值范围也在0—1之间,当它为0时代表完全透明,为1代表不透明
下面来看一张图看他们之间的区别
通过图片可以看到,使用RGBA()改变透明度的时候,不会改变文字的透明度,而使用opcity改变透明的的时候,文字的透明度也会被一起改变。
<!DOCTYPE html>
<html lang="zh">
<head>
<title></title>
<style type="text/css">
body{
background-color: cadetblue;
}
.blue{
width: 100px;
height: 30px;
background-color: blue;
opacity: 0.1;
color: white;
}
.red{
width: 100px;
height: 30px;
background-color: rgba(0,255,0,0.1);
color: white;
}
</style>
</head>
<body>
<div class="blue">this is RGBA.</div>
<div class="red">this is opcity.</div>
</body>
</html>