CSS的两种渐变

线性渐变和径向渐变

几个常见的例子效果
在这里插入图片描述

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style>
			.a{
				font-size: 20px;
				width: 100%;
				height: 50px;
				margin: 10px;
				background-image: linear-gradient(red,yellow,blue);
			}
			.b{
				font-size: 20px;
				width: 100%;
				height: 50px;
				margin: 10px;
				/* 向左边渐变 */
				background-image: linear-gradient(to left,red,yellow,blue);
			}
			.c{
				font-size: 20px;
				width: 100%;
				height: 50px;
				margin: 10px;
				/* 向右上边渐变 */
				background-image: linear-gradient(to right top,red,yellow,blue);
			}
			.d{
				font-size: 20px;
				width: 100%;
				height: 50px;
				margin: 10px;
				/* 向30度角方向渐变 */
				background-image: linear-gradient(30deg,red,yellow,blue);
			}
			.e{
				font-size: 20px;
				width: 100%;
				height: 50px;
				margin: 10px;
				/* 到20%时为yellow,20%~40%时为red,之后就是循环前面部分 */
				background-image: repeating-linear-gradient(to left, yellow 20%,red 40%);
			}
			.f{
				font-size: 20px;
				width: auto;
				height: 80px;
				margin: 10px;
				/* ellipse可以不写,默认就是这个类型,算是椭圆,但如果是正方形就显示的是圆形渐变 */
				background-image: radial-gradient(ellipse,yellow,blue);
			}
			.g{
				font-size: 20px;
				width: auto;
				height: 80px;
				margin: 10px;   
				background-image: radial-gradient(circle,yellow,blue);
			}
			.h{
				font-size: 20px;
				width: auto;
				height: 80px;
				margin: 10px;   
				/* 圆心以20% 20%这个位置开始发散 */
				background-image: radial-gradient(circle at 20% 20%,yellow,blue);
			}
		</style>
	</head>
	<body>
		<div class="a">a</div>
		<div class="b">b</div>
		<div class="c">c</div>
		<div class="d">d</div>
		<div class="e">e</div>
		<div class="f">f</div>
		<div class="g">g</div>
		<div class="h">h</div>
	</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值