CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
; w$ k2 d. W; Z; Q 以下各特效用的HTML代码相同:! ?4 S" X7 D+ P
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
4 Z- c9 X* m+ f! R1 c$ \1. CSS动画边框/ a) u( h- V4 _- Y
CSS代码:, w G3 |3 c) |4 H9 J( ~
@keyframes animated-border {
0% {
box-shadow: 0000rgba(255,255,255,0.4);
}
100% {
box-shadow: 00020pxrgba(255,255,255,0);
}
}
#box {
animation: animated-border 1.5s infinite;
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
border: 2px solid;
border-radius: 10px;
padding: 15px;
} 效果如下:
% y4 `" Y$ k. t: S- F, `
$ U8 z. i' f% h
6 s' a* p6 m0 ?2. CSS图像边框4 c! H# m& s. j) T& d9 T
CSS代码:
; G: e) y$ S/ X5 ?& r4 }; C#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
border: 40px solid transparent;
border-image: url(https://image.flaticon.com/icons/svg/648/648787.svg);
border-image-slice: 100%;
border-image-width: 60px;
padding: 15px;
} 效果如下:" V. H7 g+ m; D! B
4 J a) v( N9 x" R0 l3 _! c4 r* [* w1 K( ^) Z+ V, j
3.CSS蛇式边框
/ ?' ]" r2 J: ~& O3 q. Y- O' UCSS代码:
2 ]" L) t! I+ c: ^: i0 O#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 15px;
border: 10px dashed #FF5722;
background:
linear-gradient(to top, green, 10px, transparent 10px),
linear-gradient(to right, green, 10px, transparent 10px),
linear-gradient(to bottom, green, 10px, transparent 10px),
linear-gradient(to left, green, 10px, transparent 10px);
background-origin: border-box;
} 效果如下:
+ H9 m0 f4 z; |5 Z
( n; u; u, f! U2 R9 a# f: d4 U( e; h2 q) ?$ |5 U3 z
4.CSS阶梯样式边框) m- C0 H9 Q7 s* r" T: g
CSS代码:
) m) @& H! P! ~* Q6 n1 B#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
box-shadow:
inset #0096880005px,
inset #059c8e0001px,
inset #0cab9c00010px,
inset #1fbdae00011px,
inset #8ce9ff00016px,
inset #48e4d600017px,
inset #e5f9f700021px,
inset #bfecf700022px
} 效果如下:
+ H+ Z5 ~$ p% M: u' e# d
2 t; A) o, N; } @
! a% F5 r: d9 o6 @5.CSS只有阴影边框
* c8 d. g* g6 B) E7 R9 dCSS代码:
6 \* W7 o4 P2 ?8 ]' G% S) J( E' _#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
' s" n1 a k% J/ @* B0 \( a3 f
6 H, W* J* B3 n1 n: G% B: F1 t* j) d7 H( U& ]
6.CSS带阴影和轮廓的边框# C* i) e6 W1 O
CSS代码:
" \. v7 N& K- \0 k#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
box-shadow: 00010px white;
outline: dashed 10px#009688;
} 效果如下:, z6 ^! H5 y6 B5 N0 b
: |3 A8 p1 G" L
( P, m% z5 s$ o/ |( |$ P$ |7.CSS少量阴影和轮廓的边框
6 k. k; l. c/ I- S/ }: c* @1 _. VCSS代码:
3 G' l+ n) @3 r#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
box-shadow:
0001px#009688,
0005px#F44336,
0009px#673AB7,
00010px#009688;
outline: dashed 10px#009688;
} 效果如下:
3 K. G; h# ?. a& U- p4 M- e6 S* {
0 A+ ?+ y* l( Z
( E3 @+ J! p: [. p! y a8.CSS带有阴影的双边框
/ t8 y% P& |- kCSS代码:/ a7 {9 o6 q! ]" q$ j
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
box-shadow: 00010px#009688;
border: 10px solid #009688;
outline: dashed 10px white;
} 效果如下:2 ~8 i' e: `% A5 A2 f& a
9 A9 L; Y3 p: C1 Q/ x6 ^8 T1 Z0 B
7 }8 B* @% E! j3 z$ C! J, p9.CSS多色边框
M! g) Y8 A0 ` y( x7 s1 vCSS代码:
$ |+ T7 Y; q0 h4 A6 t#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
background:
linear-gradient(to top, #4caf50, #4caf50 10px, transparent 10px),
linear-gradient(to right, #c1ef8c, #c1ef8c 10px, transparent 10px),
linear-gradient(to bottom, #8bc34a, #8bc34a 10px, transparent 10px),
linear-gradient(to left, #009688, #00968810px, transparent 10px);
background-origin: border-box;
} 效果如下:
6 r4 `1 ` R& W* y
|