CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。, y. Y0 o) R% ^; T; D* C* o7 L
以下各特效用的HTML代码相同:
) d+ h( S i# w% b% ~* C5 [& f<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
4 M. I+ n% G' y5 B$ n* M' x1. CSS动画边框
; p8 N# I( J4 E9 Z! i2 ^CSS代码:$ G6 N0 N& E; X0 s s
@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;
} 效果如下:
) h6 W. l4 |' t1 z/ T( x
5 {( b6 ?# H( }1 V
5 ?; z6 e6 Q7 W- T3 g# e6 @
2. CSS图像边框
8 Q# S+ ~6 d( m0 hCSS代码:2 z% D& y" C' Q# 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;
} 效果如下: y9 o" D4 X& |# D( O6 x
0 V; y% l3 b; i: R7 P5 D- x+ }0 F6 j* b' v) A
3.CSS蛇式边框
K! _# h1 K( T5 E7 `CSS代码:
) o' U' {- @, F- F8 y9 T5 s#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;
} 效果如下:
6 x9 x$ \9 X# s# _ B9 D
4 S4 }/ x8 K6 b# ~! S
. S' D- \% R' K% ?* v4.CSS阶梯样式边框# r4 S$ q7 _/ E' i1 K1 H; Q
CSS代码:0 c* @5 ~7 x- K% J! B
#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
} 效果如下:
O6 R4 x! Q ?* j9 ]) W
- K4 t1 t! X- F' U8 A( _ u/ M8 |/ z
5.CSS只有阴影边框
+ N6 ^9 R! a0 w' h- V: r0 T/ r# M' rCSS代码:
! x: ]2 r$ x& 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;
} 效果如下:7 T2 @* R! p- f0 H# ^5 w
8 s4 E: L; m- d9 I
* h, D6 p" y1 y6.CSS带阴影和轮廓的边框
: o D4 ] {3 F) ~: `/ ACSS代码:! I" p* @0 F7 ` n5 K
#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;
} 效果如下:% J" ~ }7 e3 Q: ]* K! b( f9 L
) r8 J1 H1 J& O$ P! }9 s! u
0 `/ i% Q! f" P9 v7.CSS少量阴影和轮廓的边框2 c9 _7 Y9 I5 b' F6 ~
CSS代码:
1 K' X/ Z( s* Z6 Z#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 T9 e7 a2 H- L2 g/ _. {4 x1 R0 C
. ^- E8 r7 d8 d/ S, V0 F
; a0 E0 {! i$ b1 F8.CSS带有阴影的双边框
( R; T; Q7 A7 r8 ZCSS代码:, s& _( k5 M1 I7 Y7 e( r5 x
#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;
} 效果如下:; F$ P3 p7 c+ y# ?. [; `" i; w k
! ?& `6 ~1 q" z, z
; H$ p3 a' H9 K1 @+ I9.CSS多色边框2 i' M: R% k# P7 p! B- E6 e6 j* a
CSS代码:
/ u7 p3 Z$ m; L4 b/ u#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;
} 效果如下:0 X0 D7 ^* n1 E. k
|