CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。7 Z% G, B4 @, |8 e5 W5 w
以下各特效用的HTML代码相同:6 `; e( b; J* x) A- D
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> & }0 q+ `/ {1 G8 z8 E, w% K
1. CSS动画边框
: O, R) a8 m9 f$ N- kCSS代码:6 u6 f1 D# M9 r4 Q) 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;
} 效果如下:( h3 S$ `3 F( y+ {8 r( Z9 }
5 \! i8 S, t& x1 ?' }
) r2 K5 b7 U1 a0 Q2 l9 w3 x
2. CSS图像边框3 j+ q2 C7 I0 f. I" K4 C5 w) ~1 s
CSS代码:2 y- E$ }: x+ G4 s9 ^7 L
#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;
} 效果如下:! |; {( H; g- W( ^- d# e
2 y0 {" c' A1 \' a/ `& }
7 V& }' {: _: B2 F3.CSS蛇式边框$ b3 f- W+ `( v# B* P, n
CSS代码:
# \" D, B: h' R u' d+ W#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;
} 效果如下:4 A6 l4 M6 U3 W0 q' l; e- F
/ q3 ]) |; j$ N. z% r6 i8 [6 R1 F1 h* d" T- i
4.CSS阶梯样式边框$ [# D4 l( c' H( K' Q L
CSS代码:
2 t" ~, y' L$ X; H3 v& ]* |#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
} 效果如下:4 E, @; b, F. _/ F
+ a U ?) v; h8 B1 f
; r0 s* y( q% W! J" `% i( T5.CSS只有阴影边框6 ` M% N- }8 b" u1 k# ~
CSS代码:
* `1 h" L& }+ |# ?: K( E3 u) B#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
1 V, h6 {! t: k
9 Z$ f* |3 B7 ?
0 A# Z! w% n8 U) p' e9 M5 v6.CSS带阴影和轮廓的边框* B- \# Z( T+ |4 J# t, }
CSS代码:
: p; m: ~9 \+ x, s#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;
} 效果如下:2 ~& Z* l7 w, R+ h9 [1 N" M
1 o+ @+ }) r7 q2 o( b2 ~4 z( W2 {
1 ?- X/ x: r4 U1 t$ z: O- x
7.CSS少量阴影和轮廓的边框
/ f. U! |' }4 z A. S* \! o$ gCSS代码:
4 K( k2 q0 U* q6 n& c1 v2 m3 o& s9 _#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;
} 效果如下:: K, W- d. }) g q8 {7 a
* p; e4 E' ~- B5 f3 G
2 b, ]. g }- ~' {4 s% [8.CSS带有阴影的双边框0 _- r. J! a3 I) t) \
CSS代码:7 z! k8 I4 g8 ^9 W
#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;
} 效果如下:
- Z, P9 M/ t* S6 a' X6 d9 J" i5 V2 @
. U; C* l( Q1 p- i, F
7 |9 M3 s9 [" n$ @9.CSS多色边框
5 F# F8 z* m6 P! J: rCSS代码:3 {7 `5 Y/ N5 Y' x- D
#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;
} 效果如下:, y2 {) x( m* |; L0 R
|