CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。0 t! |0 y; B, S6 I! x: X: b ~
以下各特效用的HTML代码相同:
3 w0 K: s1 B+ x* g4 u/ t8 @ <div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>5 I: _ }4 u( R8 C" i H5 d
1. CSS动画边框
: q+ N, Z" _: }2 \ k9 l3 R6 X CSS代码:
7 \' E% B* Q8 W, x; Z/ k @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;
} 效果如下:
6 z8 l, V( R j; ^. } Z6 q* F9 E6 w
. K; _; [! M' O" L" } 2 D0 g4 y. W0 }0 u9 u( t
2. CSS图像边框
; q4 w& Y8 `" ]( x( F+ V& o* \ CSS代码:
: ^: `& ~# M2 c. w9 w1 h, `# c0 y6 z #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;
} 效果如下:! K1 r1 V. B& i+ j( z3 t( T
! p6 e1 Q* P) Z/ _' ?* C0 c , G9 Q5 G* V" D' P8 A2 \9 G! l7 c+ x+ E
3.CSS蛇式边框
, {- \/ r$ x+ h2 V CSS代码:
x; q! L) B+ D% f5 a5 `) D #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;
} 效果如下:
0 t9 Q& {" Q0 d0 U3 s( q+ i
7 M7 J8 L2 f% n0 z. J0 \! {
5 O/ ?1 h( v2 H5 D" | 4.CSS阶梯样式边框
0 m) u9 R7 E' g CSS代码:
$ e% H" Y& v. O5 S6 n #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
} 效果如下:
; [. i; {1 F+ {- X3 i6 m
) r$ Z4 m9 T2 s- H" J 9 e" g8 p& O- ?) ~, t& I% u- [ a
5.CSS只有阴影边框 ; B3 Q% V) n3 e7 g/ r' A1 h$ z5 X
CSS代码:
" T, H' i X1 W% |# p #box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:, {: @; ?) S6 b+ ^% W ^3 {& e
. @! M# ?: k- }, ?
) l% g5 u2 x2 l3 M' c0 g2 ^
6.CSS带阴影和轮廓的边框 5 |0 N! x7 x: H; R# G9 Z! A- |
CSS代码:
. A* t' _9 C$ m2 L4 V- j) N& h #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;
} 效果如下:9 n* K ?! H0 b+ [
B7 L: q, ]6 s
1 z' S a- ^. x9 T& S5 L9 x. l 7.CSS少量阴影和轮廓的边框 * I) z5 n: y7 M5 @, T; U2 E, q
CSS代码:, S. y* N/ B0 g5 m1 {" T3 ]; B( h
#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;
} 效果如下: D1 ]% \( g) q: K3 M
# G7 h9 b1 Z2 M) l
2 m$ h0 N2 j# I, y" J
8.CSS带有阴影的双边框 ' x8 Z7 G; U8 f: b2 v
CSS代码:1 }3 G) I; I, R0 T7 i/ A' a: @0 O
#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;
} 效果如下:: A; ]. |( f8 o5 m
2 Y% i% m( h; m: a8 P7 B
& {8 ?/ K. d& {8 h# }
9.CSS多色边框
# q, k- w& i% T; p0 ~& i CSS代码:4 p4 E2 X: i4 q; I- i
#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;
} 效果如下:0 H1 g& j6 a0 q" k% t/ \+ Y- w) A