CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
0 h8 C# x" b7 ^4 q 以下各特效用的HTML代码相同:
2 h# D1 v2 L, E' P. E4 a<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 7 U3 T# w$ Y2 }4 n( `8 O; C: a
1. CSS动画边框
: Y2 _/ t/ w( ^/ R, K- h6 gCSS代码:3 s+ i9 ~. j2 d! O
@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;
} 效果如下:' i, g5 j+ i) t. W2 W
- A A8 n# A1 F. g; L+ B5 g: W- p$ ^+ w7 c( `& ^& s
2. CSS图像边框' t3 W7 M: f) J' i( U R6 X+ @
CSS代码:
8 z, Z% o8 p" @+ z# }; F) P#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;
} 效果如下:' j$ |: U6 {6 t
$ u7 f. n+ }% r( ^5 r
' I$ U( D& E* c$ j l. S& X
3.CSS蛇式边框
4 g/ n; W0 s0 |- ?1 bCSS代码:
0 }5 e/ h8 i& M H1 s7 d& C0 C#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;
} 效果如下:
+ U- r) o% D" r% W, i: o% w
* z" b; z# C3 P6 r' z/ f
9 v+ E" j: } A* o, j# |/ j8 T4.CSS阶梯样式边框# b0 T! {6 a/ H) I( k
CSS代码:
1 K- M: y0 x' Y4 y& J#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' \8 l0 @" e8 D2 A4 @
1 f) ~8 |0 m7 O4 m6 @0 S) Z8 O6 ~) y" v& H9 L. J6 [7 ]2 }
5.CSS只有阴影边框% N2 Y: p, K' R! G) }2 Q. y
CSS代码: r0 G' Q- Z+ 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;
} 效果如下:
5 d; q4 w: Y9 b: R( F9 L' ^
1 e2 k6 L* \/ w9 ^# G2 l
* e _6 }0 ~/ c& |7 G- B& Y
6.CSS带阴影和轮廓的边框/ C# q2 b4 c0 T$ ^* W: |8 z5 ?
CSS代码:
6 k0 d3 p2 ^. z6 ]+ 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;
} 效果如下:
& u- m, Q1 q8 c2 f, @
+ q, B) N, q0 ]* T$ w* n
5 r) \" K2 x1 O: a) E0 s7.CSS少量阴影和轮廓的边框
9 \8 @$ D4 g2 V' E6 u7 }$ x3 D# I% NCSS代码:* N: ^. D0 r2 \$ I
#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;
} 效果如下:, M: `* X" w7 g& f( V, Q
" ]! Q9 G3 K8 B8 `& r+ F
: `! c! H" R6 \, H1 u4 E7 g8.CSS带有阴影的双边框
. z8 |& l+ P, C9 T5 K; j Z- wCSS代码:
* a( K c [! m$ j9 k/ y#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;
} 效果如下:3 y S, J9 l S& I% C
4 }) ?- y1 }$ L$ Y. B
! R4 G3 u1 D6 q8 T6 c: ?; y! P
9.CSS多色边框& F+ R8 s4 E" W' i
CSS代码:. b+ m0 O6 Q6 P4 Q1 ?4 m* N
#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;
} 效果如下:
- c; x T8 b' B8 K: p
|