CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
- `. L; N) j! j( Y 以下各特效用的HTML代码相同:+ Y) c ^9 _4 w; z
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
# z! y' s5 W$ C, Y% j) `+ l6 ?- o1. CSS动画边框; P: I3 T) o- e0 l
CSS代码:
3 r% k( l1 H. _1 @@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;
} 效果如下:: ^/ c' ^1 F3 L
; A" @/ D* ~4 |! m% m; ]
( r: G. @; S+ z* ?
2. CSS图像边框5 p G" F, p# S ^ |
CSS代码:3 z4 u) W/ T/ y- C h- s K
#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;
} 效果如下:
; G- [& i* e5 \9 x
7 _/ B; L. E) x: i
. ?0 ]4 {9 p/ o/ K3.CSS蛇式边框, ^; n: Y% F; ^$ g9 X6 J2 L- b
CSS代码:$ {3 Q V5 C- e( }& N
#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;
} 效果如下:
( |; c7 J2 F$ l, E' G3 j5 ?
" j* q3 R- T( [ ~5 m7 M
0 |6 U) ]' _: b7 `0 b/ M( }4.CSS阶梯样式边框& Q+ O6 V/ h0 z$ j; ~$ t
CSS代码:
& g" u, i F5 N) D# G* 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
} 效果如下:
0 s. O! F0 M, U$ u( Y
; y) ~( s9 S5 t6 A, x6 z) @! j' Y; T1 Q" J
5.CSS只有阴影边框/ Z; ^- }0 T* b8 ^/ j
CSS代码:8 A [5 y' K( d; _9 i* Q9 T# F1 {# r
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
2 q) Y2 x; l2 `# p
9 T6 ^5 D8 B8 F3 N. H
' V6 X- j& b- F: r6 n6 \' O1 H6.CSS带阴影和轮廓的边框0 ]* F# W+ a& b7 e' U; ^: I' A# O8 r
CSS代码:+ i4 J: l/ }9 Z4 W9 E6 _
#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;
} 效果如下:
5 F/ z, a4 S, O9 q5 J
& x+ ]+ [, g, Z3 X- e
# v. L0 {1 ?( i* s- ^7.CSS少量阴影和轮廓的边框( U2 C! }' [$ h% g; U( b4 g
CSS代码:$ X+ @$ q8 G) v( K( |& a/ V3 Y; a6 q
#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;
} 效果如下:
2 i4 {! ~0 J9 N, I" F( }. B0 ^
4 \; L' L4 t9 B$ t# R4 l; I$ b8 E n& s& ^) E
8.CSS带有阴影的双边框) A3 p9 W# L1 t+ h* s$ j- ?
CSS代码:5 s, j8 E" t, m9 _0 y; e' K
#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;
} 效果如下:
9 i' P" c) H. e/ l) d0 E8 ~( I$ }
" W' O: p2 Y7 }9 V* y2 D- e5 y! M6 i
9.CSS多色边框
! n- N3 ]% o, i/ RCSS代码:
/ j' B' ?8 i; D9 A) L, R#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;
} 效果如下:
$ G/ b, ~( |" |1 J: W/ J# l
|