详解:39 css3新增颜色属性 hsl hsla rgb rgba

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style>	
		div
		{
			width: 300px;
			height: 300px;
			border: 1px solid red;
		}
		.box1
		{
			background-color: #000;
			opacity: .5;
			filter: alpha(opacity=50);
			color: white;
		}
		.box2
		{
			background-color: rgba(0,0,0,0.5);

		}
		.box3
		{
			background-color: hsl(0,100%,50%);
		}
		.box4
		{
			background-color: hsla(9,35%,55%,0.73);
		}
		.box5
		{
			background-color: rgba(180,112,100,0.73);
		}
		.box6
		{
			background-color: transparent;
		}
		.box7
		{
			color: pink;
			border: 1px solid currentColor;
		}
	</style>
</head>
<body>
	<div class="box1"></div>
	<div class="box2"></div>
	<div class="box3"></div>
	<div class="box4"></div>
	<div class="box5"></div>
	<div class="box6"></div>
	<div class="box7"></div>
	<div class="box8"></div>
</body>
</html>

在这里插入图片描述
在这里插入图片描述

opacity: .5;
filter: alpha(opacity=50);

为什么要联合写,因为filter: alpha(opacity=50);只有ie支持,其他浏览器不支持,opacity: .5;这个ie不支持这个。其他浏览器都支持。
两个都写的话,那哪一个浏览器都支持了呀。

background-color: rgba(0,0,0,0.5);

最后一个是透明度,0~1之间的透明度。

0(0%)为透明,1不透明(100%)。

background-color: hsl(0,100%,50%);

HSL即是代表色调,饱和度,亮度三个通道的颜色.
h:Hue(色调)。 0(或360)表示红色,120表示绿色,240表示蓝色,当然可取其他数值来确定其它颜色.
s:Saturation(饱和度)。 取值为0%到100%之间的值;
e:Lightness(亮度)。 取值为0%到100%之间的值;
最后的a代表透明度。与rgba的a一样的取值。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

贵哥的编程之路(热爱分享)

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值