CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
: \1 R8 i( w. V. B- x% u/ } 以下各特效用的HTML代码相同:, t/ }3 ^ ]! w. `3 h [! V- ?
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
0 p( Q. ?9 i T: y) M4 C" a1. CSS动画边框- d5 v( O* ^! f
CSS代码:" Q- S7 g( N, H( ^0 h% X) i
@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;
} 效果如下:
2 S' A7 @. f# Z, }5 J
* w. Z5 C9 \3 m0 J8 X
6 G1 X, Z. _1 N' | H9 }, {
2. CSS图像边框
- }. u5 Y7 F: _/ o: n. gCSS代码:3 ?4 E5 E' [! f' n
#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;
} 效果如下:
+ `* M% i1 O& |% [: V( }
9 J: m; t' w9 e1 F3 Q
2 a9 j7 E# X, T/ d2 V; z0 w/ P8 G3.CSS蛇式边框
! B! o- M% t6 E- _ r1 uCSS代码:- |* Y0 Q+ b2 O
#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;
} 效果如下:; Y9 H, S) U: O3 F/ t, B. E
, [! f b( a4 n" s
; }: x; N' X6 ]6 o) t9 U% L
4.CSS阶梯样式边框2 J5 F- e4 `- C H9 R$ L
CSS代码:" v8 w4 |- J) z' T$ X: \
#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
} 效果如下:: N8 ?- q' ^' @" x
! l0 r0 B# s+ X8 F1 e" I
c3 R5 ^& S! i \4 `/ n) a) Y6 G
5.CSS只有阴影边框
" N `/ g" B4 y' |& ?3 b( E7 NCSS代码:) \! s- Y$ K0 e7 \4 d5 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;
} 效果如下:% _7 T) e' B! ^0 [) \8 S
d7 \2 h: ^9 s7 c E8 J+ t( \, @- Q8 I% `5 I4 m. k% w
6.CSS带阴影和轮廓的边框
2 N& Y ], y, _) O: w- L" E: yCSS代码:; P/ G6 [$ |( V
#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;
} 效果如下:
! S! E8 O; ?( _( Z/ J
( v& L4 j+ N# p* a2 [ s2 r
3 n: R. M' I8 w- \+ L1 { d+ u3 S/ k- p7.CSS少量阴影和轮廓的边框% O8 R1 Q+ U7 `# F s
CSS代码:) S) y1 D5 V% H5 b1 |& X/ e; T
#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;
} 效果如下:5 Q) h7 a- t, `6 i2 _7 z3 A
' U A+ x% s1 t( F# Y" T2 v4 b/ |# ~
7 F3 d) Y' I2 @7 g- G& U9 x9 Z3 n8.CSS带有阴影的双边框' q$ Q# {+ s, D6 `/ J# B$ U t" Z
CSS代码:9 E0 ~0 X" U" x- G0 N6 d9 o7 R7 l
#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;
} 效果如下:
0 M2 K; }$ c* w; q4 x! @
7 Q8 B" r+ w# n; n) O2 g
( c* k: B( V! c9.CSS多色边框
1 J6 m1 x) r4 U. T% Z4 g. ICSS代码:
/ k4 F- w/ H& m i& 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;
} 效果如下:
0 M9 ^. `5 d1 G* A$ _( |, o
|