CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
/ k5 C$ A$ {5 ~& @8 I; i 以下各特效用的HTML代码相同:5 `8 K' L* N/ m" j; g" A* v
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
N7 r1 q" c& }7 p0 c) Z( j6 m1. CSS动画边框) Z; z6 N7 \: j" x
CSS代码:
( I0 I+ S9 u3 ?6 h5 q@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;
} 效果如下:( Z; m( z, D1 y
4 f. N+ {* F/ @, ^4 }* @, S6 k, r
! e: \7 Z" n$ [( u% |
2. CSS图像边框
8 ~" R, P) W1 Q. A1 nCSS代码:. d) `, V& x) g7 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;
} 效果如下:! C; t2 j! K( S, ]* M
: m/ n" D2 E( J3 X/ ^: A
1 ^" Y1 i$ T9 P t+ l3.CSS蛇式边框* R9 w0 z( l4 |
CSS代码:: B$ T, o# Y" m3 v& z# ]
#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;
} 效果如下:$ m7 C' Y( `* y. d/ D
4 {; o8 {6 `# u1 @
$ l0 `! f- M% E/ t4.CSS阶梯样式边框+ W. ~9 W9 I) O8 v4 u- l# q
CSS代码:. C7 Y2 W& E# m$ v% J
#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
} 效果如下:7 o. t( `3 f, u9 M
, K4 h$ V- |( p6 h& T, h
# }& R x5 R6 n- O* d/ J" F& Q
5.CSS只有阴影边框: @4 |8 V7 k* M
CSS代码:
3 d' d. g. h5 i/ s#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:" t6 }7 i& `4 c: Y; u9 k9 @0 o
, C' P. x# {1 c5 D! q0 G4 _
5 q8 z2 Q2 T1 A8 t" I6.CSS带阴影和轮廓的边框
% F# s: {, N' I% ICSS代码:
4 l1 ^1 A- M1 w. L# Q8 n( Y& P6 }0 T#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;
} 效果如下:: L! ~1 f* Y9 j
( \3 V4 @" e: s) n D
4 H! C# l/ J4 b* O4 M& m' y7.CSS少量阴影和轮廓的边框
: H& S. d+ R6 J2 b' F" \# qCSS代码:
- @8 e( J: C" A; ^3 d- {# j" Y#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;
} 效果如下:' T+ f* d) G* i9 S4 j
& k7 }3 L! J% }) ^7 d+ L6 {7 [, o
# K/ g+ F- @ ]. t' l @9 \9 x7 g8.CSS带有阴影的双边框4 V& ]5 I& q" p
CSS代码:* F: D% L5 U8 ^1 W) ?! 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;
} 效果如下:
5 O6 t/ J- ]5 u, J. c) q$ Y/ N
2 ?( K1 l: L5 X( t% {3 G- [; j
+ i' [! `4 s6 D L
9.CSS多色边框
4 |" p) D, Z4 S" vCSS代码:
7 ]. w5 |- R( N8 g. Z1 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;
} 效果如下:/ Z( E- c) v3 e# Y
|