CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
! X9 `6 Y; X$ P; Z 以下各特效用的HTML代码相同:$ {/ V, F; W. t, G
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
2 x( V' R6 _" J/ i 1. CSS动画边框
9 q; i: X3 M- i, H( j CSS代码:7 h! t9 w$ N9 `4 X6 y
@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;
} 效果如下:
! x! V. N4 A G2 \
4 h8 q E9 D7 h5 H6 H* @. V
9 X9 G* K+ W. [1 y8 G) {& P( ^
2. CSS图像边框
4 o4 n' t# ~& |' D, F" Y CSS代码:% t, O. K, q8 b& X# m
#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;
} 效果如下:5 E# o3 v5 x% g$ d- @
$ ~* ?9 z- i0 W3 L
: B. T0 v% a, u7 M' M
3.CSS蛇式边框 : a" O( p+ [! S3 G" T; C" ~
CSS代码:: W9 a/ J3 ~1 Q+ V) e& z! R
#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;
} 效果如下:
+ l/ v7 l: a4 h1 J3 u
. _3 z1 O6 U+ }; \$ S. J5 `. a( ]
0 o' w. r+ |/ w- }; j& F
4.CSS阶梯样式边框
" Y: h1 e' u9 z/ y5 U CSS代码:
) P2 J5 t3 |& R B8 \ #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
} 效果如下:5 T% s' b" D8 h
* V1 M8 S: s* k0 I( C7 M
7 B! K, Z( q7 n" o+ J7 Y. b$ O$ w1 m* W; k 5.CSS只有阴影边框 ; ^7 r- u: V x+ b- Y
CSS代码:
7 c, y/ C0 w) V1 t M% Z/ | #box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
. o7 I9 i' O, m+ A: z X' I3 d
; j7 J4 m O, {( f. N3 I 7 g/ a1 ]# z9 H2 x
6.CSS带阴影和轮廓的边框 # P; w8 ]: r6 c' K+ y, a' S
CSS代码:9 ^& Y7 t' ]. F4 W. m. F: ?
#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;
} 效果如下:' x3 s; w3 A _4 b0 y# v& K U# [
/ \9 M/ f3 k+ w5 z* Q6 ~' h
3 I- v! ^9 r/ T4 _6 q2 ? 7.CSS少量阴影和轮廓的边框
/ @6 k% N7 y5 C# F" { N CSS代码:, a+ n& s. b% M6 b. R
#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 @3 R( j: o+ |. g4 _
3 N" `; L; I1 s5 q
' ?: q7 a8 F9 D+ y B! y2 a% s
8.CSS带有阴影的双边框 9 V' P5 v, a8 E! r: e6 A1 x8 g8 D
CSS代码:& \; f# _" Y. J) j; \- u
#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;
} 效果如下:7 z0 h- P# i3 K7 _, @
& h/ y$ h p1 ~# U9 y7 Y
( r8 I9 X) u" E 9.CSS多色边框
N: T* l; Z- U0 ] CSS代码:' @0 P0 _9 S& h2 l! Y4 @3 k0 ~
#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: b2 d& u9 E3 k" C, q