CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。% V& Z$ A0 n6 i9 T. k
以下各特效用的HTML代码相同:* N( U8 @* Z( C3 Y* {: W* d( k
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> & x" V5 b/ R F. W. L- ?
1. CSS动画边框, T. _- e; R" k
CSS代码: e' W0 b" A3 H P1 `
@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;
} 效果如下:
$ a+ i* w+ m L. ?
1 y/ p2 v" [8 Z; l Y6 n, G% J
: ] f+ P: o; @! L
2. CSS图像边框8 I5 V$ k, u) B: G9 p; a& a
CSS代码:; {; Y3 n& R( U4 W
#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;
} 效果如下:6 }4 S/ R- E# ~( v! d! S; y
, p7 [2 L* I _+ X2 n/ Z8 w& s0 z
3 m; c9 S9 V: I; ^3.CSS蛇式边框
# G7 `, A0 x5 _& i6 f) m5 p: T9 ~CSS代码:
3 Z8 L$ d% L- G2 N' a) j+ W0 w0 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;
} 效果如下:
/ w/ e z2 a2 d# q# q8 k, f) J% t
6 }! s8 o& o2 \; w
7 ~+ _% u \6 @! Y$ R9 g4.CSS阶梯样式边框( N' v7 j" i" w
CSS代码:
5 h" _- l- h0 |- `, \8 ]#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
} 效果如下:$ `# H( a/ H, E% w' J8 h. q; I
" U7 L- z: L# a# ^% q% d: @
. x0 X3 D% j( [5 Y
5.CSS只有阴影边框
! v: c( o9 B: f! y' a' o0 e& dCSS代码:
: L8 ]. R9 R' d; D# L#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
. k. T4 ~/ y8 t6 N- Y5 n
& j E: P c V
0 ]$ B: y- Y9 ]1 A; X
6.CSS带阴影和轮廓的边框- o3 n f4 H2 {8 o8 M- i
CSS代码:
) k2 R* V4 Y6 h' @! M' v! J#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;
} 效果如下:
% D5 c. G K( y! H
# f; {7 P3 m; t/ R4 A; w. C! X% {% H: ~7 V% M# t
7.CSS少量阴影和轮廓的边框% x* L/ |5 |6 ^; x
CSS代码:3 M0 L/ V' g8 ~% ^5 Q& f- 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;
} 效果如下:
/ [( J6 ^* G+ h0 B
3 S s1 ~# b7 h3 v! j5 Z, P, q7 o; l
U; Y) X5 l( o, g+ d% y4 p8.CSS带有阴影的双边框
7 a' B! p- K2 {CSS代码:
% C: w+ Y8 J, x0 }#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 s2 m1 r5 E2 l4 G
4 O! N5 J, q ] w& m- y. h; y& c
* c" P* M& i1 q: `( x9.CSS多色边框
" x) Z$ W: \- M9 o( j& TCSS代码:
4 S, P3 l& N3 |. G" M% }#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;
} 效果如下: W! M5 m X7 t3 D% N
|