css 集结令

不间断记录css小技巧

shape-outside 设置文字环绕

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 /* 关键字值 */
shape-outside: none;
shape-outside: margin-box;
shape-outside: content-box;
shape-outside: border-box;
shape-outside: padding-box;

/* 函数值 */
shape-outside: circle();
shape-outside: ellipse();
shape-outside: inset(10px 10px 10px 10px);
shape-outside: polygon(10px 10px, 20px 20px, 30px 30px);

/* <url> 值 */
shape-outside: url(image.png);

/* 渐变值 */
shape-outside: linear-gradient(45deg, rgba(255, 255, 255, 0) 150px, red 150px);

/* 全局值 */
shape-outside: initial;
shape-outside: inherit;
shape-outside: unset;

层叠感

1
2
3
4
5
<div class="wrap wrap-0">
<div class="wrap wrap-1">
<div class="content">哈哈哈哈</div>
</div>
</div>
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
.wrap{
background: transparent;
position: relative;
top: -10px;
border-radius: 10px;

&.wrap-0::before{
content: '';
display: inline-block;
position: absolute;
background: #fff;
bottom: -10px;
left:30px;
right: 30px;
height: 30px;
border-radius: inherit;
box-shadow: 0px 2px 24px 0px rgba(200,201,204,0.5);
}
&.wrap-1::before{
content: '';
display: inline-block;
position: absolute;
background: #fff;
bottom: -12px;
left:20px;
right: 20px;
height: 30px;
border-radius: inherit;
box-shadow: 0px 2px 24px 0px rgba(200,201,204,0.5);
}
.content{
padding: 10px;
background: #fff;
border-radius: inherit;
box-shadow: 0px 2px 24px 0px rgba(200,201,204,0.5);
width: 200px;
height: 200px;
}
}
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
<template>
<button class="gradient-button">
渐变边框按钮
</button>
</template>

<style lang="scss" scoped>
.gradient-button {
position: relative;
padding: 12px 24px;
background: white;
border: none;
cursor: pointer;
font-weight: 500;

&::before {
content: '';
position: absolute;
inset: 0;
padding: 2px;
background: linear-gradient(
45deg,
#12c2e9,
#c471ed,
#f64f59
);
-webkit-mask:
linear-gradient(#fff 0 0) content-box,
linear-gradient(#fff 0 0);
mask:
linear-gradient(#fff 0 0) content-box,
linear-gradient(#fff 0 0);
-webkit-mask-composite: xor;
mask-composite: exclude;
transition: opacity 0.3s;
}

&:hover::before {
opacity: 0.8;
}

&:active::before {
opacity: 1;
}
}
</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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<template>
<div class="gradient-borders-demo">
<!-- 基础渐变边框 -->
<div class="box border-basic">
基础渐变边框
</div>

<!-- 动画渐变边框 -->
<div class="box border-animated">
动画渐变边框
</div>

<!-- 悬停效果边框 -->
<div class="box border-hover">
悬停渐变边框
</div>

<!-- 圆角渐变边框 -->
<div class="box border-rounded">
圆角渐变边框
</div>
</div>
</template>

<style lang="scss" scoped>
.gradient-borders-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
padding: 20px;

.box {
height: 100px;
display: flex;
align-items: center;
justify-content: center;
font-weight: 500;
color: #333;
}

// 基础渐变边框
.border-basic {
position: relative;

&::before {
content: '';
position: absolute;
inset: 0;
padding: 2px;
background: linear-gradient(45deg, #12c2e9, #c471ed, #f64f59);
-webkit-mask:
linear-gradient(#fff 0 0) content-box,
linear-gradient(#fff 0 0);
mask:
linear-gradient(#fff 0 0) content-box,
linear-gradient(#fff 0 0);
-webkit-mask-composite: xor;
mask-composite: exclude;
}
}

// 动画渐变边框
.border-animated {
position: relative;

&::before {
content: '';
position: absolute;
inset: 0;
padding: 2px;
background: linear-gradient(
90deg,
#12c2e9 0%,
#c471ed 50%,
#f64f59 100%
);
-webkit-mask:
linear-gradient(#fff 0 0) content-box,
linear-gradient(#fff 0 0);
mask:
linear-gradient(#fff 0 0) content-box,
linear-gradient(#fff 0 0);
-webkit-mask-composite: xor;
mask-composite: exclude;
animation: rotate 3s linear infinite;
}
}

// 悬停效果边框
.border-hover {
position: relative;
transition: all 0.3s;

&::before {
content: '';
position: absolute;
inset: 0;
padding: 2px;
background: linear-gradient(45deg, #12c2e9, #c471ed, #f64f59);
-webkit-mask:
linear-gradient(#fff 0 0) content-box,
linear-gradient(#fff 0 0);
mask:
linear-gradient(#fff 0 0) content-box,
linear-gradient(#fff 0 0);
-webkit-mask-composite: xor;
mask-composite: exclude;
opacity: 0;
transition: opacity 0.3s;
}

&:hover::before {
opacity: 1;
}
}

// 圆角渐变边框
.border-rounded {
position: relative;
border-radius: 10px;

&::before {
content: '';
position: absolute;
inset: 0;
padding: 2px;
background: linear-gradient(45deg, #12c2e9, #c471ed, #f64f59);
border-radius: inherit;
-webkit-mask:
linear-gradient(#fff 0 0) content-box,
linear-gradient(#fff 0 0);
mask:
linear-gradient(#fff 0 0) content-box,
linear-gradient(#fff 0 0);
-webkit-mask-composite: xor;
mask-composite: exclude;
}
}
}

@keyframes rotate {
to {
transform: rotate(360deg);
}
}
</style>