CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。: b; }, V4 K, ^" c! j' {
以下各特效用的HTML代码相同:
: ?! A' ~, h; U6 L <div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>+ l j& p- c7 O/ N
1. CSS动画边框
) Y2 s, G7 ]4 ?+ x) Y! k! @ CSS代码:
7 G- A: L7 m+ g0 I; o @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;
} 效果如下:
0 o' ~, j9 l, _3 E' R- M2 t
# N1 U) a, |" a, ^ 9 N, W t: v1 r, e
2. CSS图像边框 ! o% B- e+ H# Y6 W( x6 P- i+ B
CSS代码:1 x/ b y8 D- H ~5 h* 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;
} 效果如下:. ?# {! l& Y* J7 X" t4 F+ r& c
. O8 {2 ?7 W, \% W4 J0 E8 p 7 D$ u% m1 U0 S
3.CSS蛇式边框
. x, f) C5 l' [1 b: Z CSS代码:. W) F a5 z4 I/ F* J( `: E5 r8 O
#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;
} 效果如下:* k- p; |" X0 {- k4 P3 M A
. Y, `! U% x V
& q! Z( V; x$ H& ~0 d r0 p& s% N# w 4.CSS阶梯样式边框
4 R! O4 T- C- Q/ ?1 ~* t CSS代码:' e/ P( P% ?' u( P/ ?
#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" F8 |4 k, _; J3 A
, z; U" m( c8 p
+ P2 |) i# J+ G# |- W 5.CSS只有阴影边框
+ J: d# a9 w* s: n CSS代码:
1 j% m+ p' i1 Y, s* `1 w* t #box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:# G$ L, X, e: {1 i* H
- \! \0 V+ d F" Q2 e) P3 y/ X
6 D u/ o1 a0 S2 s; j! E 6.CSS带阴影和轮廓的边框
# T' d3 f L( v: z! l CSS代码:
* K4 `/ i- Q |; u- i ~# [ #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;
} 效果如下:
, a! B' O7 d% s( T# K5 a2 L
) e. d8 b- m) T- D5 o$ x: M 9 [$ q4 S; x2 ~6 G
7.CSS少量阴影和轮廓的边框
: a; S ?1 i2 [ [# T. Q, g CSS代码:
: O, D, g: J, Y" U# [' l Y. @2 @ #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;
} 效果如下:/ R" r6 q' q/ g: g5 U! P
8 \5 ~; @+ q# u6 M4 {# U
% Q" ?/ [ k! o, I
8.CSS带有阴影的双边框
5 V/ T4 [+ Q% ^) B3 J' s7 Q& r CSS代码:
9 [4 `$ Z' \- e1 u #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;
} 效果如下:& z7 m" g, U" e& v$ ^/ ~* E
. B& m- {1 ]- s2 Y0 x
, z) r$ S* F, c# K5 f4 O+ k
9.CSS多色边框
* v" z }, g. p8 v) b8 S CSS代码:5 A# Y1 t4 a3 X( \7 R* 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;
} 效果如下:# U1 E- D( h5 O9 n( f# ]6 ], l; u9 e% R