CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
4 [5 r7 l+ P. e, m& u4 Q 以下各特效用的HTML代码相同:
, W y( U. h2 S6 S<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
) B! w( O3 T: i3 c7 }1. CSS动画边框 d D( o3 ~) i2 k
CSS代码:
: Y6 b1 X: D: u! n; v7 @/ ]@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;
} 效果如下:" t1 I+ D1 [& w- q
) u9 {( H) p+ d8 R; J. E
1 v- Q# W" ^. r" s# j
2. CSS图像边框$ q6 h1 G. r# e) h5 I
CSS代码:$ u) }" ^% ]1 P) x: `! f+ 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;
} 效果如下:& B+ t0 s9 H8 ]7 j7 a r# J
* F3 m5 r* ~, _2 u/ g3 N2 }8 ^
- A6 L5 {8 M) G; e3.CSS蛇式边框 y3 Y2 H% N$ X$ A
CSS代码:: c: A# Y, H& C( n- 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 A2 |: e: ~7 M! }# R3 ~
# ~* Z9 u" x- x0 ~
, }: v8 `# b2 y! v+ `. n
4.CSS阶梯样式边框
0 T' \+ g3 \+ H O. W _. ZCSS代码:
- k2 ` V! ~1 J0 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
} 效果如下:/ V1 V: C( x( R) @
9 { c* C1 a: s8 D i3 D
# j' g O. O) O' H* X. ~0 z4 K5.CSS只有阴影边框
! S4 K+ m/ {5 R. y+ w( B9 U, QCSS代码:5 w: i2 j# O, N0 X" h/ g
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:+ |6 \9 J6 E5 _ E, O) k8 L
' x, E6 B, F, N( o9 d
0 B% ^* q5 E7 n6.CSS带阴影和轮廓的边框
' l8 O, g$ k2 Q# L. DCSS代码:3 b! Z7 v- R2 N; a1 O
#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;
} 效果如下:
1 W7 e1 h/ {/ m6 G! J
" m$ M9 y6 W. H/ F$ K6 T: s2 F6 [, [- I, T# {
7.CSS少量阴影和轮廓的边框: B; M- g% L8 E3 X0 N1 U) X
CSS代码:
8 d/ S, ?; n8 }* H" G#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;
} 效果如下:
$ j) b4 X, q: M' O7 |
1 {$ a4 |& C" C3 F; {# h9 l
/ B5 N( [* n) \: J; B6 ~/ R8.CSS带有阴影的双边框
7 H( k" J* M* oCSS代码:" ~& B7 u) G1 B, k3 }
#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 b1 t# X/ }! e3 {+ D% p, h
+ `" @2 w6 B7 d' N9 T) l2 Q: L e- V
9.CSS多色边框
, c" ~) w% L# K9 b8 v& O0 C+ aCSS代码:: o6 d3 K6 E% g* j+ ~/ L# g
#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;
} 效果如下:
& R% |, A. X5 C7 d0 ^2 l A( V f
|