CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
, V' c' O( |: y& N0 H+ S 以下各特效用的HTML代码相同:! J0 c/ S S& v" M j) ^2 N( @# _
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
8 ~$ h' _. ~5 q3 F- h6 I 1. CSS动画边框 ( s/ D9 s- l; D& D2 H' Y4 V t
CSS代码:' b' K! G- }5 M; C* x- |
@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;
} 效果如下:
_& Z2 p. B' n: e' f% K
" I6 s6 Z6 ^: N! ^. g& W+ g6 ?# k
8 [7 k( e+ N: h# |' L6 I 2. CSS图像边框
% N" ]3 t; m; u v& l- z$ s CSS代码:! H0 W1 x$ E8 q5 l1 W3 s9 Y
#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;
} 效果如下:0 P, A, o |. n
* n: J- L' v4 g R b& m9 r& y9 v9 U0 @# F( p
3.CSS蛇式边框 ) n; \2 e' S3 T' q
CSS代码:, S6 Q% z+ E: W% f! G. 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;
} 效果如下:
% }5 Y" s# j7 u2 M" a( V0 z
}5 W6 v/ O1 J
! ~" X; L' f0 j* q9 s+ H1 R- H 4.CSS阶梯样式边框
- |( F9 y) l9 H# E8 p CSS代码:" ]3 J/ D& P% ~2 y: Q
#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% h) q. M' q: W
, X# e7 ~) N& q ) \* o0 e, Q6 C; S1 u( |1 p( R9 W
5.CSS只有阴影边框
4 n4 \ ?6 f# [$ y CSS代码:6 U- B. u# b+ J m5 {5 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;
} 效果如下:" t' `) s9 l$ T5 d* n
; ]$ u0 {) i9 b3 Y
0 G: m4 O9 Z: `
6.CSS带阴影和轮廓的边框
( k4 V# _ C0 n CSS代码:$ J* h5 d, S8 x7 v0 G$ y- `
#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;
} 效果如下:
. ?! |# j. o1 U/ j9 @9 }9 d6 |) c
7 U n \1 d4 b) J$ u # f" Z& v2 [7 g, C b) n) G4 A
7.CSS少量阴影和轮廓的边框 0 I8 e" H) r7 u4 r
CSS代码:
3 U) E3 O( F3 T9 s9 D W #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;
} 效果如下:" B S8 _/ N6 N" ?" W& C1 w1 E8 g
2 Q( N! h8 n- G2 V
1 l# [) [9 y+ @: U5 o" | 8.CSS带有阴影的双边框 0 Y. A" D( ?2 m
CSS代码:9 i- I! C M! u, d
#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;
} 效果如下:
$ e' d$ w3 g& p4 m) h7 s/ V
& U1 O$ r; b( G7 [0 M2 G : b' ]" c" a8 h
9.CSS多色边框
" H8 d( d: Y" A$ S! b+ z3 ` CSS代码:
& N# ~4 ]6 ` M( O #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;
} 效果如下:
* W$ k/ x! w# G9 J/ F