CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。/ R, Y' e2 m' m* K/ [" z+ h
以下各特效用的HTML代码相同:
5 z, F# M3 E- O J* t. a0 g<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
! Q' j% k, m7 g$ U3 W1. CSS动画边框
2 @* b( L- f: @% J* U! tCSS代码:
9 T$ ?5 _$ g i) P@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;
} 效果如下:) v' l$ H, S1 {2 V5 d
) `. ]* {' L) o: `) R! \5 }
3 p" i: l1 L7 Y a% \& s' h" a2. CSS图像边框
% }: F$ c& v0 T, A V4 GCSS代码:- }8 [; I% U9 i- `. K$ ~
#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;
} 效果如下:
% P. [; o! y1 O
$ c, _3 {; x( n8 v
+ d+ Q. P3 @! _4 e
3.CSS蛇式边框
- k+ t- q" Y& t5 o3 xCSS代码:2 _& V2 n9 u* W ]- k4 [1 p
#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;
} 效果如下:! \2 F8 X! \: n) r" f
8 k3 c/ {/ t+ c( | J m2 j
! _1 n) V# u- W- I* ]$ S$ b4.CSS阶梯样式边框
/ B1 z" u6 G, H! w7 a2 ^- H+ MCSS代码:
( v1 _7 y! i& _+ s' A8 F( S$ v/ f#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
} 效果如下:$ Z$ `( X* B C; P9 P
$ R) Q- Y+ _$ |" g/ t
3 [ n; U( Q) @( C: d
5.CSS只有阴影边框1 q z1 V8 I* A
CSS代码:/ D6 p) L: K) K) Q2 p) 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;
} 效果如下:
0 x% f: j8 W( p" J/ K
; f: x) z9 p/ [* P9 a9 V. [4 D" `5 h% o- X$ K
6.CSS带阴影和轮廓的边框0 ^; o7 R# N9 ~" x8 Q
CSS代码:
5 e% H* o. }* x& J. U% Z5 `#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 e j2 B: c! ]! k7 x) \
! G- Q: j B$ G- F2 K
; A* c9 Q7 z6 q. W$ Q2 \
7.CSS少量阴影和轮廓的边框
! I5 r2 g6 F. Q0 I- k1 B) [1 zCSS代码:6 x) x/ N1 a2 `0 K9 S8 ^! \, H
#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 }7 v+ }' Z/ q. K
* l! u( m/ l- C+ G7 e) Q. E
5 n* R- T6 A1 B' ^" T/ e8.CSS带有阴影的双边框6 c/ z1 f+ J d7 z/ S* t7 e* c
CSS代码:' \3 J$ H. K; @5 ^! A
#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;
} 效果如下:
8 O1 u6 L. B* }4 z4 T U
1 c: | ~$ E+ E: N
% r- J1 Y- n9 `3 W- |9.CSS多色边框
/ \) u: _. }; w! R( w$ ^% ^8 nCSS代码:& O, U {4 B8 L
#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;
} 效果如下:: m ^- s& o, V/ S# T
|