CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
% U0 N: d2 W" Y* a7 C) n 以下各特效用的HTML代码相同:6 H" X) v- _/ A f7 [
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> ( w) w3 P6 j$ G q
1. CSS动画边框
]" `+ k; \; v1 HCSS代码:
* [; R2 |& a+ M6 @# B/ {@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;
} 效果如下:5 A% V' {9 c& y6 }: H' \/ N7 t6 M P& _
" x1 c* w+ d# a x
v4 K1 d$ _+ W2 b7 F ^: I7 f
2. CSS图像边框
, V8 t' u7 t0 D. [CSS代码:
. N6 X. Q5 n- u5 K9 X3 u& ]#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;
} 效果如下:
. _$ x9 l1 v v7 d4 F5 x
v8 B3 a$ o# R9 @# ^
9 Z/ a: R. s8 o6 w8 h3.CSS蛇式边框+ R4 l' ^* m# h' i4 x
CSS代码:
, s( a3 }1 E% c# ^; X7 F# ]4 s6 h4 Y#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;
} 效果如下:
& e* i& g. [. M4 X K! t
: Q# C1 ]& e( I" [; ^% r& J+ ^6 _* y+ i
, k9 ^: n; ] X/ d7 F( c5 j) i3 z4.CSS阶梯样式边框% w, v z: ]& `/ _( V/ N6 o6 a
CSS代码:
; p" n. ]" P9 p#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 [ \& @0 w2 M+ a, g3 W' @
6 O8 I- q4 `5 I
9 D' K2 ~& W/ a- e) l+ b5.CSS只有阴影边框
! D( R, d9 g& V7 z/ VCSS代码:
5 ], B( b7 F4 l4 m% S5 T#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:, G' b( \. x# ~) }, i& X
: ?0 L) q1 A; b8 @7 q! w. |; k/ ^1 _
6.CSS带阴影和轮廓的边框
6 h9 ^$ K& e4 ]! ]6 q0 {CSS代码:
! X0 I2 u. C& ~& V9 K0 C#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;
} 效果如下:
/ |1 f% R: L! r1 F, Y. s
( F4 |& e" P: d" {; n5 x
- T' n5 b0 U1 a% D7.CSS少量阴影和轮廓的边框& n8 F* ?! v. Y" w5 }* x
CSS代码:. u" _) s5 d( F4 I* G! U. t
#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;
} 效果如下:
1 d% Z- @0 y* I$ n
6 n" }4 i# P3 S$ c9 p$ m! `
' K" ~2 B5 Q' W6 z& T8.CSS带有阴影的双边框
1 }- A; z+ `; O' Q: o8 p* I0 B, z4 oCSS代码:
) B) R: I$ {/ |#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;
} 效果如下:" Y, u+ e. a) n7 f4 K0 _. m4 y
4 h* B) D- @7 X; N R0 h! g
0 Y, r i! z, y0 p9.CSS多色边框
6 f. T+ g A+ J# k6 ^CSS代码:& j! o9 P: T: @* \, Y* _
#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;
} 效果如下:
& Q' H; D5 {4 m1 G% Z- s
|