css的渐变效果

目录

1.线性渐变

1.从上到下的渐变

2. 从左到右的渐变

3.对角线渐变

4.使用角度的渐变

 5.使用多个色标

6.使用透明度 

7.重复线性渐变

 2.径向渐变

1.均匀间隔的色标(默认)

 2.不同间距的色标

3.设置形状

 4.使用大小不同的关键字

5.重复径向渐变


1.线性渐变

1.从上到下的渐变

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>线性渐变</title>
<style type="text/css">
.box{
		height: 200px;
		background-color: red; 
		background-image:linear-gradient(red,yellow,blue);}
</style>
</head>
<body>
	<div class="box"></div>
</body>
</html>

2. 从左到右的渐变

<style type="text/css">
#box {
  height: 200px;
  background-color: red; /* 针对不支持渐变的浏览器 */
  background-image: linear-gradient(to right, red , blue);
}
</style>

3.对角线渐变

<style type="text/css">
#box {
  height: 200px;
  background-color: red;
  background-image: linear-gradient(to bottom right, red, blue);
}
</style>

4.使用角度的渐变

取代预定义的方向(向下、向上、向右、向左、向右下等等)。值 0deg 等于向上(to top)。值 90deg 等于向右(to right)。值 180deg 等于向下(to bottom)。

<style type="text/css">
#box {
  height: 100px;
  background-color: red; 
  background-image: linear-gradient(90deg, red, yellow);
}
​</style>

 5.使用多个色标

<style type="text/css">
#box {
  height: 200px;
  background-color: red; /* 针对不支持渐变的浏览器 */
  background-image: linear-gradient(red, orange, yellow, green, blue, indigo, violet);
}
</style>

6.使用透明度 

如需添加透明度,我们使用 rgba() 函数来定义色标。 rgba() 函数中的最后一个参数可以是 0 到 1 的值,它定义颜色的透明度:0 表示全透明,1 表示全彩色(无透明)。

<style type="text/css">
.box {
  height: 200px;
  background-image: linear-gradient(to right, rgba(255,0,0,0), rgba(255,0,0,1));
}
</style>

7.重复线性渐变

repeating-linear-gradient()属性

<style type="text/css">
box {
  height: 200px;
  background-color: red; 
  background-image: repeating-linear-gradient(red, yellow 10%, green 20%);
}
</style>

 2.径向渐变

语法格式:

        background-image: radial-gradient(shape size at position, start-color, ..., last-color);

默认地,shape 为椭圆形,size 为最远角,position 为中心。

1.均匀间隔的色标(默认)

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>径向渐变</title>
	<style type="text/css">
	.box{
		height: 300px;
		background-image: radial-gradient(red,yellow,blue)
	}
	</style>
</head>
<body>
	<div class="box"></div>
</body>
</html>

 2.不同间距的色标

<style type="text/css">
.box {
  height: 150px;
  width: 200px;
  background-color: red;
  background-image: radial-gradient(red 5%, yellow 15%, green 60%);
}
</style>

3.设置形状

shape 定义形状。

 circle 或 ellipse 值。默认值为 ellipse(椭圆)。

<style type="text/css">
.box{
		height: 300px;
		background-image: radial-gradient(circle,red 20%,yellow 20%,blue)
	}
</style>

 

 4.使用大小不同的关键字

size属性

  • closest-side
  • farthest-side
  • closest-corner
  • farthest-corner(默认)
<style type="text/css">
#box {
  height: 150px;
  width: 150px;
  background-color: red; /* 针对不支持渐变的浏览器 */
  background-image: radial-gradient(farthest-side at 60% 55%, red, yellow, black);
}
</style>

5.重复径向渐变

repeating-radial-gradient() 属性

<style type="text/css">
#box{
  height: 150px;
  width: 200px;
  background-color: red; /* 针对不支持渐变的浏览器 */
  background-image: repeating-radial-gradient(red, yellow 10%, green 15%);
}
</style>

  • 14
    点赞
  • 42
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值