颜色的赋值:
1. 通过英文名称
2. 通过rgb三原色调配比例,来赋值
3. 通过16进制位数,来匹配对应的颜色
opacity 透明度
取值范围 0~1
1 为不透明, 0为完全透明
rgba(): 4个参数 r g b a
a : 透明度
必须要四个参数,一个都不能少
<style>
.box{
width: 100px;
height: 100px;
background-color: rgba(200,100,10,0.6);
}
</style>
<body>
<div class="box"></div>
<script>
var box = document.getElementsByClassName("box")[0];
function c(){
return Math.floor(Math.random()*255);
}
//通过使用 rgb三原色 来完成随机颜色的赋值
box.style.backgroundColor = 'rgb(' + c() + ',' + c() + ','+ c()+ ')';
</script>
</body>