CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。) U3 X: d4 o% n. z( {! r% e6 G7 ~2 Q
以下各特效用的HTML代码相同:
% V$ [2 M, C) W* ? H6 b9 c: i<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> ' }" V S1 X* E( ?
1. CSS动画边框5 Y( p, h' f/ h) Q2 N
CSS代码:
0 F% C- M9 o* M" e' a, |6 v@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;
} 效果如下:4 z- ~( ~+ L7 L. s% Q5 N. Z
8 A1 O( ^$ @7 ^6 x& y0 ^+ k+ m; y
. E9 `# Z# o& S( v6 A
2. CSS图像边框
/ l7 w v2 W- t1 @8 TCSS代码:2 I" f" w5 d: Q' T. V
#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;
} 效果如下:6 c9 M" Q" ], i
/ U+ v7 g* p% z6 w2 Q2 s
' d3 \5 n/ D9 S# O: K7 V+ a3.CSS蛇式边框/ L) l1 f( y3 s8 V, x' f0 ^! v# _
CSS代码:
6 U6 C3 i# L) g4 d2 b#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;
} 效果如下:
, Z# \5 b7 T9 ]) C
& I0 u, l2 h! e8 F7 Z( w
. L ]9 B5 Y$ L4.CSS阶梯样式边框* G+ d" |. J! p; S/ s; \3 C
CSS代码:. B9 k/ Z3 D& O# I
#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
} 效果如下:& ]2 L' w& r8 `5 G2 [
% Z# `, e; l& n- |2 V+ _
3 K! ^% y/ G' c' i2 j- u5.CSS只有阴影边框
% S* |" ^. _' u7 f7 W8 lCSS代码: N1 f' F) j) @, e; ^2 d- a% L
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:( N! w1 l+ N: x& }3 i/ { C; L
: ^# C* z6 [6 m: ]% U! _. S) y h& i2 Q
5 p1 k9 z3 p( M% d$ H0 Y4 s4 A9 q
6.CSS带阴影和轮廓的边框) _1 ]% D e) M- U
CSS代码:6 L) v2 ~& \. j& U( _4 ]
#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;
} 效果如下:
; T1 w X: l5 [" O* x
) u0 A/ p8 I2 x3 o- t9 | ^2 s# H. _2 W
. d% ?; y; j6 F! o1 s' o8 f& n: ]0 w3 c7.CSS少量阴影和轮廓的边框; a/ D' p/ K1 x: H6 u* c8 |
CSS代码:# i" r& R J3 n. k* z
#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;
} 效果如下:
$ a6 ~) D6 A/ j$ @# b/ Z
! w( H% Q% I8 o2 [. N' u8 y
+ a. ~, E7 _0 g6 d4 _
8.CSS带有阴影的双边框
% T! B: |0 m8 r3 n. p2 u) JCSS代码:
$ V4 J/ o; }) H9 j% C#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;
} 效果如下:
) x+ L# n& R/ @3 ^" h/ A: O8 e* F8 D
+ K+ z; ?# T$ ~0 c
' Z9 G$ s" S" ~" _$ F: C" w( a7 ?
9.CSS多色边框
& W( c) m9 W% [; O3 ACSS代码:
, X( m. e( [3 t0 J5 }+ w; Z#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# p% ?$ p' p9 q( @* S/ d7 X4 g
|