CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。: g5 W6 P+ z, F) d$ i
以下各特效用的HTML代码相同:2 v/ q! w) g* k
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
* p2 U; k8 G8 `, v9 {1. CSS动画边框
/ I* w6 |+ w: d7 [CSS代码:
# G, S7 V$ R0 |( l0 w, B2 C \@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;
} 效果如下:
' X; A/ K/ n6 f9 Y2 e" L$ F
1 [# _7 J$ ~+ B! W* I" D& h, {, M: J2 Q; K
2. CSS图像边框1 P( R3 x. U7 }2 U) _
CSS代码:7 k2 u4 t" u: n. Z$ o
#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;
} 效果如下:
* |, r. w a' L! G; w8 e& E' G
3 Z" b! Z3 @0 |; ^. }) S2 z, _1 H# S" X! ^! c* b. W
3.CSS蛇式边框
6 L6 h4 x0 q$ |$ Z n, D: mCSS代码:
4 r; ]% L: h9 b+ |2 u% r1 v+ ^#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;
} 效果如下:
/ u2 i9 g4 g7 o& S- ~6 X2 l
& n! S" K& H- |7 O, r8 p
& @7 O( t; h% i. u- ~4.CSS阶梯样式边框" g6 d! [: Y/ S2 S# W) k
CSS代码:
9 E$ Q) A. P( K. ]6 ?6 t#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
} 效果如下:6 y7 [1 `2 e2 c. U' {* E% `
3 O n6 h% Q1 f0 V' u- K
0 y+ g# z, }, J8 c! o8 f0 v
5.CSS只有阴影边框7 f+ }& t% E) ^9 P e
CSS代码:
! J8 y4 F5 F! C; ^7 }, ~. ^#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:+ K) z* j$ T* a( W h; l
8 w! l) U# l. K; M& u
0 E0 u$ c7 C$ j# {6.CSS带阴影和轮廓的边框2 J4 t2 ~& w3 m4 E
CSS代码:& Z( D2 J* G, S$ E( Q# L8 b5 r1 S
#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 X% z5 P M- y4 `$ p0 {! b
. }3 G9 x# w/ F; J+ H# F# q* A
5 m, K& F" p% G7 g8 G7.CSS少量阴影和轮廓的边框
: f4 E! m( o/ c" n9 ^CSS代码:% _% O( O4 B: Q, 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;
} 效果如下:
( M7 |, ?) |: v w! o0 L7 o: x
" b/ F3 I5 y5 O, @ u' t
* n$ _5 @5 r! Q4 @" ~% W) u- t. ?8.CSS带有阴影的双边框
4 O/ f; t, d" { M2 }3 ZCSS代码:
8 I4 I8 R( f$ C- O8 q6 b: e#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;
} 效果如下:$ R+ o$ p2 w9 O, h$ y" v) ~5 b
3 T/ F. R: ?' p0 O! c
2 f! V7 f! ]: I0 K9.CSS多色边框7 n6 p9 r8 N0 M* n/ L" y; N
CSS代码:2 ]2 q" R' U9 y- V9 J% _2 e& 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;
} 效果如下:. O( E5 ~1 p- s& y$ W6 j
|