CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
* D9 S' b* O; y" |6 a7 ~( G! W 以下各特效用的HTML代码相同:& J- B7 o! {" _4 r+ s, v8 g
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 3 M: I* K) N1 `# Q% m
1. CSS动画边框
1 |# M$ R! h- m L3 dCSS代码:$ b9 T x7 n4 _3 T K! t
@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;
} 效果如下:
- G1 w/ d$ z$ L9 w: D F2 C! F
7 ~) X' T2 S, A# _/ ?2 l+ s
, @, @; K5 v# |$ x# i7 V( G% h
2. CSS图像边框8 {: ?. e5 \7 X3 l! H' ~
CSS代码:5 W+ X4 E3 x: O8 i$ z
#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;
} 效果如下:" q( P! Z( n. l2 c) |2 e! j U" A
X% h% {( v0 k: e: E0 C9 _* u2 ^+ l& B
3.CSS蛇式边框1 @: E3 e8 Y Z5 r9 ]
CSS代码:) P% Z3 W- Y# t
#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;
} 效果如下:
; ^. l( q' m* t K" ?
7 L6 M; [& f5 x, ?/ H
8 @+ n4 t% b! i$ Z4.CSS阶梯样式边框6 h' G9 S" w2 }& h: E8 O0 `3 x1 [
CSS代码:; D; y/ }+ p O
#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
} 效果如下:
! v M% Q# P- T5 I8 G6 h. d
d% V6 Q, u: P! H( \) j( C
/ J+ k0 ?6 Y; Q; j3 F( p! Y5.CSS只有阴影边框
6 |+ @' w( |2 p5 B+ mCSS代码:7 Q ^: |$ Q% b) t/ V9 p
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
, C7 P# n0 r+ [( S
/ _! A/ |3 F% t9 G
* M( n* S3 F! w) [& v' \' h; ?
6.CSS带阴影和轮廓的边框! |$ p, i6 j x* l, U
CSS代码:; ?$ s0 S! a, P Z
#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;
} 效果如下:/ P( W4 ]" ^: }! r4 Y
" C) {- f7 N, L: O
# j; M7 E6 b- @/ S3 I8 w7 X7.CSS少量阴影和轮廓的边框
: L# c3 z9 I0 P8 S: k* g( bCSS代码:
% f( p7 z9 C1 _ J1 Y; f9 J" o$ v8 }#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;
} 效果如下:2 E' o9 \ u. m
/ n C, C7 m9 Q4 K9 h: w6 `+ L
/ F- }. n" s' H2 ~0 b3 y8.CSS带有阴影的双边框
7 `6 e9 r' I5 {0 p3 cCSS代码:
: C" y& D4 h) i0 f2 g#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;
} 效果如下:
! q# h" D7 ^+ k% Q# }! h) ?& g
* w! a0 b/ b: u' d& R/ }) @+ u( L! m
9.CSS多色边框) X5 E5 p! w7 u
CSS代码:
, B3 S; [# S- f. G, Y8 z8 A#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;
} 效果如下:( E3 G' V- c' w# X
|