CSS3 线性渐变 linear-gradient


可以设置水平和垂直位置为百分比,或以像素为单位,或在水平方向上可以使用left/center/right,在垂直方向上可以使用top/center/bottom。位置起始于左上角。如果你不指定水平或垂直位置,它将默认为center。其工作方式主要包含:Top → Bottom、Left → Right、bottom → top、right → left等


效果图:



代码:

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>CSS3 线性渐变</title>
    <style type="text/css">	
		*{margin:0;padding:0;}
		.linear_div *
		{
			width:200px;
			height:200px;
			margin:10px;
			float:left;
		}
	
		.div1
		{
			background: -ms-linear-gradient(top,#ccc,#000);
			background: -webkit-linear-gradient(top,#ccc,#000);
			background: -o-linear-gradient(top,#ccc,#000);
			background: -moz-linear-gradient(top,#ccc,#000);">		
		}
		// 左到右
		.div2
		{
			background: -ms-linear-gradient(left,#ace,#f96);
			background: -webkit-linear-gradient(left,#ace,#f96);
			background: -o-linear-gradient(left,#ace,#f96);	
			background: -moz-linear-gradient(left,#ace,#f96);			
		}	
		// 上到下
		.div3
		{
			background: -ms-linear-gradient(top,#ace,#f96);
			background: -webkit-linear-gradient(top,#ace,#f96);
			background: -o-linear-gradient(top,#ace,#f96);	
			background: -moz-linear-gradient(top,#ace,#f96);
		}
		// 左上到右下
		.div4
		{
			background: -ms-linear-gradient(top left,#ace,#f96);
			background: -webkit-linear-gradient(top left,#ace,#f96);
			background: -o-linear-gradient(top left,#ace,#f96);	
			background: -moz-linear-gradient(top left,#ace,#f96);
		}
		
		.div5
		{
			background: -ms-linear-gradient(left,#ace,#f96,#ace,#f96,#ace);
			background: -webkit-linear-gradient(left,#ace,#f96,#ace,#f96,#ace);
			background: -o-linear-gradient(left,#ace,#f96,#ace,#f96#,#ace);	
			background: -moz-linear-gradient(left,#ace,#f96,#ace,#f96,#ace);
		}
    </style>
</head>

<body>
	<div class="linear_div">
    	<div class="div1"></div>
        <div class="div2"></div>
        <div class="div3"></div>
        <div class="div4"></div>
        <div class="div5"></div>
    </div>
</body>
</html>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

俊刚、

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

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

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

打赏作者

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

抵扣说明:

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

余额充值