CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
: C1 f' i# X: H8 ] 以下各特效用的HTML代码相同:2 w2 r2 O [3 ]; {5 }$ e
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
# x4 Z' u) P) Z" ~& T2 B1. CSS动画边框
/ u& i% f/ O* v1 G( W, J* OCSS代码:
; W5 O) I8 F; w$ g2 R@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;
} 效果如下:" `* f% x. l8 l
' |# _0 Q0 S6 L9 j) S* m
6 q" v4 u' J' j7 W* t8 ?; B
2. CSS图像边框
% e7 ^9 G) @, H! _1 Z2 xCSS代码:
% ^4 p8 Y% [+ }- e6 U+ J: k$ t2 o1 q#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;
} 效果如下:+ U! R1 ]- T- j R$ |
- J% C5 U* x# K6 c4 c( F/ H
& x' s3 S0 U4 P, F9 I3.CSS蛇式边框
" v% d6 R" v* K. `. LCSS代码:6 h: y" t+ c3 J# {0 b' [7 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;
} 效果如下:
/ S/ ]7 g# [0 e0 J
8 z1 C! b7 @$ U: f
' U: c6 B" ?9 }/ q4.CSS阶梯样式边框7 o, d o3 \7 |" z
CSS代码:, j8 D; T7 l- B6 U3 ?" n
#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
} 效果如下:
, T9 u4 F' n: E) V* ~, G1 Q
" L* M3 k/ o7 \9 G! J' E1 |& Z8 _. n: q u; P/ K" A3 Z
5.CSS只有阴影边框. Y5 U4 l! Y, v+ C2 Z. O4 r
CSS代码:2 ]0 D4 O) s+ @5 [& Y4 d; F* v
#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% r* M U! J
v( @5 w8 g; a, _8 R! }5 C
- ~0 m1 l# p; t- M. M/ d+ H1 N6 q
6.CSS带阴影和轮廓的边框 R" L) I1 \& e
CSS代码:
1 C; W8 l2 \; n& v- L#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;
} 效果如下:8 a# E9 m9 O8 p, m% E( X
5 S. v* J: h# L- G/ E1 r2 Q5 C7 f( a# j1 ?' M7 G: @4 J1 Q) x
7.CSS少量阴影和轮廓的边框+ W. C, q. t, ?
CSS代码:
0 ]3 P! B" p5 x#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;
} 效果如下:
) G- i( G, A" q( `! c E
$ g% z; G4 _7 g `, E
# @- z4 P/ K* M8.CSS带有阴影的双边框
1 F! O1 T/ i- m+ X9 a |+ ?! TCSS代码:
6 g# |" z, _+ j* X7 K#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 G& F6 ]* B: H
; Z' v r' S' D" a, C$ G7 Z
2 L0 M3 i0 D3 c- X, u3 k& y9.CSS多色边框8 A8 ]3 P/ B( }$ n
CSS代码:
& [) q2 |" z# a' t* I5 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;
} 效果如下:8 I6 _* C0 G( {$ O
|