css3渐变的使用
# CSS渐变的应用
# 渐变边框
效果展示:
点右下角Codepen按钮查看效果。
这里示例不知道为啥没效果,但在浏览器可以正常运行的
具体代码:
<div class="border-image-pesudo">按钮</div>
1
.border-image-pesudo {
font-size: 18px;
color: #ffffff;
text-align: center;
cursor: pointer;
width: 144px;
height: 48px;
line-height: 48px;
background: #FFADD2;
border: 1px transparent solid;
border-radius: 31px;
position: relative;
}
.border-image-pesudo::before {
content: '';
position: absolute;
top: -5px;
bottom: -5px;
left: -5px;
right: -5px;
border-radius: 31px;
background-image: linear-gradient(135deg, rgba(8,151,156,0.94) 0%, rgba(24, 144, 255, 0.93) 50%, rgba(255, 77, 79, 0.98) 100%);
z-index: -1;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 边框流光
效果展示:
边框流光效果使用到了CSS3的一个属性:clip-path。它使用指定的裁剪方式创建元素的可显示区域,详情请看这里 (opens new window)。
inset
是按照矩形区域进行裁剪。
具体代码:
<div class="content">
<div class="anim"></div>
</div>
1
2
3
2
3
.content{
width: 550px;
height: 280px;
background-image: linear-gradient(90deg, rgba(254,187,5,0.80) 0%, #FE8A3C 100%);
border-radius: 32px;
position: relative;
/*transform: translate(0,0);*/
}
.anim {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
transition: all .3s;
/*z-index: -1;*/ /*如果父级没有使用transform:translate()那么z-index:-1也不用加*/
}
.anim::before {
content: "";
position: absolute;
top: 0px;
left: 0px;
right: 0px;
bottom: 0px;
border: 5px solid #fff;
transition: all .5s;
border-radius: 32px;
animation: clippath 12s infinite linear;
}
@keyframes clippath {
0%,
100% {
clip-path: inset(0 0 98% 0);
}
25% {
clip-path: inset(0 98% 0 0);
}
50% {
clip-path: inset(98% 0 0 0);
}
75% {
clip-path: inset(0 0 0 98%);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 流光按钮
效果展示:
具体代码:
<body>
<a href="#" class="colorBtn">button</a>
</body>
1
2
3
2
3
<style>
.colorBtn {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 230px;
height: 90px;
line-height: 90px;
text-align: center;
color: #fff;
font-size: 25px;
text-transform: uppercase;
cursor: pointer;
background: linear-gradient(90deg, #03a9f4, #f441a5, #ffeb3b, #03a9f4);
background-size: 400%;
border-radius: 60px;
}
.colorBtn:hover {
animation: animate 8s linear infinite;
text-decoration: none !important;
}
.colorBtn::before {
content: '';
position: absolute;
top: -5px;
left: -5px;
right: -5px;
bottom: -5px;
z-index: -1;
background: linear-gradient(90deg, #03a9f4, #f441a5, #ffeb3b, #03a9f4);
background-size: 400%; /*将背景色放大,再通过动画移动背景就实现了流光效果*/
border-radius: 40px;
opacity: 0;
transition: 0.5s;
}
.colorBtn:hover::before {
filter: blur(20px);
opacity: 1;
animation: animate 8s linear infinite;
}
@keyframes animate {
0% {
background-position: 0%;
}
100% {
background-position: 400%;
}
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
在GitHub上编辑 (opens new window)
上次更新: 1/20/2022, 11:27:12 AM