CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。9 {6 D: I4 L+ j0 [+ k0 u
以下各特效用的HTML代码相同:; C" J3 [) H Y: z
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> - H$ J" v5 P8 f9 U
1. CSS动画边框
0 L# K% W) _$ _4 I/ O& [CSS代码:
/ e& U+ s% H5 O! x: ]" f@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;
} 效果如下:
3 a0 ?$ Q8 c( N9 f
" d4 V4 }" H2 T, ?0 [: x/ W% R
4 W- k/ y9 n. E
2. CSS图像边框0 V1 h+ y V: v9 w
CSS代码:0 B$ i1 n: G( @0 h1 R
#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;
} 效果如下:
" x- O, U1 f& `% ^
$ d7 t+ t# n) L7 z$ l. b- e5 `# H4 B
3.CSS蛇式边框6 ? h9 \ H' q7 P9 R4 G
CSS代码:
q- ~( \/ O( l. \( _5 S2 f#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;
} 效果如下:
( v% L" ^# m. ^5 P
4 R- N! l" l8 V
3 N" h+ P0 x9 h% ~- _8 @
4.CSS阶梯样式边框: B' L. A( M& ~$ Z1 t0 a
CSS代码:, I3 h6 q4 B+ M3 E. K
#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
} 效果如下:
# `! s" a7 d9 `2 \9 l
' b- v% r$ y0 M, [" P( ?4 T8 ^. x ?
5.CSS只有阴影边框# f* C, q6 g" @8 _% u& n. i
CSS代码:: \2 M$ ~6 R, |7 Q. }1 ?' Z& j' |
#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 i" s# F" i+ J, f
' e* B; V, A @, g5 v$ n
4 ~) G$ }' ~$ z6 x6.CSS带阴影和轮廓的边框
# p/ n9 A9 u8 ~7 aCSS代码:
% v& B7 m" _# V, z0 R. c3 V#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;
} 效果如下:
3 X- B. K( I' Z+ X. _
! Q, G8 e* q) |- d' k
" V0 A) Y$ U& M+ e' l3 e7.CSS少量阴影和轮廓的边框2 }3 k' \) g( P# F
CSS代码:
4 W7 Y- J3 m; B3 A#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;
} 效果如下:
6 P: b0 i1 ~" |! P9 q
1 c w! o& |" ? i: d
" T1 D& F+ M& l' P9 U8.CSS带有阴影的双边框
! h6 c* R. z& r% ~( \2 ?9 ACSS代码:& ~2 D% y5 [( I% d
#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;
} 效果如下:
: ]4 J. D7 `7 z
4 q7 O+ k. S3 @/ p5 A- s0 K1 |
+ R% L! C' Z) `- E+ b+ _* T" ~9 u6 e
9.CSS多色边框
" ?4 s2 z) l) p) ^! v9 KCSS代码:/ N+ a5 C) L. V3 U v
#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;
} 效果如下: p- ]1 ]! n- z7 ^/ E
|