CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。( Q7 g/ I, z1 E# X1 w. |- Y2 y
以下各特效用的HTML代码相同:
; [6 F. W# o$ ^- e<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
- R; O. X. z1 V: [1. CSS动画边框
5 ?. p, _# Y( GCSS代码:1 Y8 I( r- s9 f$ s
@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;
} 效果如下:7 `+ }( C" [' ~! P5 X$ [; G
' ~' b2 Y7 `$ {' G4 H# D6 o; s* { k" q9 p3 r1 k( Y
2. CSS图像边框) ^9 n! R) u1 z' Z' I0 G
CSS代码:
# c! m. @6 ]" C2 P, S9 y% H#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;
} 效果如下:* P) N1 [. ]) X, g$ B$ ]/ a+ k
! \* c/ l" j0 x; b6 q. @
3 A5 q2 Z+ m4 Y4 l. w4 s
3.CSS蛇式边框
0 ]6 l1 D9 A( w) @9 o9 Q0 F% d! d, _CSS代码:. I" B+ l7 K( V/ T5 z+ \5 r4 g4 A$ Q5 P
#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;
} 效果如下:! X# J7 X( X, N0 U& }& z4 J
0 {( t$ ~0 B5 T2 Y
( m# g5 \) a/ V# D! [. _8 R: \4.CSS阶梯样式边框
9 R4 V" \- u) _CSS代码:) r n- C, y+ U8 A
#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: N |# L; o9 F/ ?9 O
4 t: p5 a& m& k% ~* e
5 H; @4 B2 w1 O4 |/ m* k5.CSS只有阴影边框$ c' ^0 o% f( I9 U$ a5 U2 j5 C, o
CSS代码:; x w7 j- M! B) f$ \( P% T- M
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
; Z. h& \: S# m" n' A
! b) x F! y/ h( u& e! D( E+ J
# Y& d C8 n# C3 [& ]6 `% R6.CSS带阴影和轮廓的边框3 x- l5 D9 E' i/ c1 G, y3 k# `
CSS代码:: t4 e2 U* v: ]( O; _8 Q% v' n
#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;
} 效果如下:
; B, q! E/ `5 X
. O r! C( ^* L& K. [5 e
" f4 U5 v; c8 {1 K( {; I' M
7.CSS少量阴影和轮廓的边框
# }* C* R- l3 ~- m" u) @CSS代码:
% \& E0 f) z, U d#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;
} 效果如下:6 x: ^2 @( p4 |2 r. J; Y
# l3 J. F7 V; I; {( U
& P1 t x$ i6 U5 I, o1 h8.CSS带有阴影的双边框9 D# F/ u) i0 W+ `. R
CSS代码:* C; i; L8 W0 |( i+ Z
#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;
} 效果如下:
. H' [1 O/ `, g" _$ J4 c
! u6 C/ z& h; {& M `( M X
; a3 X; K, a- y. l; c9.CSS多色边框1 p7 |9 f4 n% u" f
CSS代码:& X/ ^1 |# m+ ^' w: S
#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 p& J H k2 [' o
|