CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。( {3 I# G* {) ~; q$ }. G
以下各特效用的HTML代码相同:
) ^: N& |0 l- ?3 h. H <div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>( b5 \3 p- U6 E7 J) k* d
1. CSS动画边框
; |( Z; P( q) i8 t- T CSS代码:7 W6 J H) }3 D$ s
@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;
} 效果如下:+ O. S0 m9 q' [
- L! l3 N* T, n( p c# f( N
" m8 F/ `9 n3 c$ A1 p
2. CSS图像边框
* X0 a% R/ B2 h4 g CSS代码:
) R' `/ Y# j5 E+ Z #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;
} 效果如下:- q' t* _$ x3 F9 w8 L
$ U: W u: _( Z' H* W4 S2 {
# l% M) O" i' J& | 3.CSS蛇式边框 6 e* \4 ?5 Y, G" P2 `) o
CSS代码:
+ B3 \7 R2 `6 Y J# d/ x: { #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;
} 效果如下:6 E+ }& R, @( _! b: Y7 O$ \* b
6 I4 C0 t7 n, o# L+ x, t! A : `5 z3 G8 _' C2 E
4.CSS阶梯样式边框 9 }" ^; l5 W, A% N, S" I
CSS代码:
' s8 H; m. R2 A: s. i3 Y; u #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
} 效果如下:
1 C$ L0 k2 \7 ^$ h* ^; i
: C/ `. g. n: F/ h+ v0 {
1 V. |+ ^5 A6 S. _6 Q/ g* d- u, r7 y
5.CSS只有阴影边框 9 r5 i, e8 |, x% o p
CSS代码:
; I; k4 C/ |- `4 O/ 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;
} 效果如下:; T3 ?! f3 v% l5 B, E: @
- c4 s: U! k; k* i, F
& H: g2 \7 `2 S$ R9 x3 {% H 6.CSS带阴影和轮廓的边框
7 ]7 F1 l w: @+ x( \$ F7 ] CSS代码:
5 z, l- x5 g1 f7 v+ Q* p #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;
} 效果如下:
4 w6 d$ ]- a/ H
O3 i; G2 k3 N: J6 b0 ^. A6 k' y {/ Q7 x2 x# d5 ?& | k
7.CSS少量阴影和轮廓的边框 9 I4 ]. @" s; N9 U7 r
CSS代码:
$ m* B+ j: p% P( l, C7 D7 N* N% B #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;
} 效果如下:. ~) u2 Z3 v/ `/ I7 `( y5 s
9 {8 k( M8 P6 p B I
- z2 {2 g& B0 {. a* l8 r 8.CSS带有阴影的双边框 + _/ O* |+ ^8 B) e5 \" E& ]& Y: y
CSS代码:
6 e/ N4 T; A( N" \& h #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;
} 效果如下:
V! ^( I6 b9 g7 r/ I' }
3 b( u" S, _! `7 `: E' ?
& B2 O1 X/ p$ G# t6 v: ?6 \
9.CSS多色边框 7 L5 h/ T% R, s L/ H+ P* H4 `! w A
CSS代码:' Z) o; p1 j0 \9 V- T0 C( a( w6 h6 f
#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;
} 效果如下:
* E# ~- `8 M& ~, y