CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
' W4 F$ ^. c4 k# c* P: J1 l 以下各特效用的HTML代码相同:
+ g5 y' V, _8 `# T+ @<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
/ V- G1 Y% `% `5 o8 x4 O1. CSS动画边框
. P ?8 l) f e r% p. X9 s$ ~0 G% E8 OCSS代码:
* H l( ]# h/ @* R4 E3 v; }@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;
} 效果如下:0 J' q% d' v9 y' f
0 H$ w% p8 b X/ C1 G8 g" G' F/ G3 }$ z
2. CSS图像边框
& m5 c0 T ]: E/ nCSS代码:
8 F# ?3 \, g8 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;
} 效果如下:: k- i: Y5 y0 c) C w1 C7 \
- G* j+ T$ Z! x6 z
5 `" I X2 ^# I2 {0 @% c3.CSS蛇式边框
! I7 Z( r, j* R2 [( ^CSS代码:1 L' D7 g ?7 f4 S
#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;
} 效果如下:' K# c W6 a$ `* a
, x9 e1 [/ ?' m- L$ n$ R( ]
; e o. S, N& N/ I: t" [
4.CSS阶梯样式边框
* r2 B6 V. b; n Q1 x' ICSS代码:8 G9 l# U6 j1 i- W
#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
} 效果如下:
8 o. x2 Z6 L% \8 Y
4 o; r+ E `6 N
. g- q) d% G, O- q% E5.CSS只有阴影边框% n, z) @: {; L; x7 \; N
CSS代码:2 K# W: }0 X- X0 G8 m9 W O% r' q& K
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:& Q5 h! e! K8 S; [: l
. P$ u4 | Z3 A Z9 p" I9 O; z* p# r4 J" }
6.CSS带阴影和轮廓的边框, z' [/ K( H$ Y) W) R4 l' J, Y7 H
CSS代码:
$ S7 H; U% g: X4 M* i$ Q( w#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;
} 效果如下:, o6 T5 x) R$ Y# W3 s
( W/ v$ }* ~1 o) F
! r9 a. E \2 U
7.CSS少量阴影和轮廓的边框 M9 k% T! u. d
CSS代码:9 _! D, A* p' r$ H( ^; o
#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;
} 效果如下:' L: s' _2 y: r% S
9 j0 ~) f. ]% i
. B6 g( B+ X9 D8 E6 A$ c8 ?8.CSS带有阴影的双边框
6 T& u' d1 E5 i X. eCSS代码:
* s! q- K& z3 m2 \3 ~3 {# ~/ b#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 i% P8 S+ b4 I0 X% C$ a# H
# M1 d1 w, \# i5 a
, W. p R! f- Y9.CSS多色边框6 T& ~) D3 y9 C
CSS代码:
7 }* ~9 X! E) P6 Q }#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;
} 效果如下:
3 P/ R& z. \' R& O
|