CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。. R' m6 ]+ u5 h. m
以下各特效用的HTML代码相同:
R& h6 F) [2 s/ b C% h<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
$ K& ~$ I# u" {+ ~! K! h- F3 L1. CSS动画边框7 y, l+ T" d" Y1 o
CSS代码:
3 N9 f3 _4 a/ d5 Q- l( ]@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;
} 效果如下:1 w- n5 H$ ~1 }2 c
! b; z" I% f" {+ ~7 _, z3 R
$ @) A, q- Q$ } \6 z% W
2. CSS图像边框
) Q; l- K1 Y# E% B' \CSS代码:
' w+ T! X7 h" D$ ~1 u#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 u& I7 J9 @" O6 w8 }( `6 ?
5 K8 K5 @0 x/ V% Y& i* F, Y+ B: P
6 x/ j1 y: e$ K( m4 h5 {3.CSS蛇式边框
3 M5 D) N' Q; S; G8 KCSS代码:
2 @2 |- c" T" q#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;
} 效果如下:5 W c1 C% [/ h r
" P2 N2 O, z; x5 ], v% Y" r X1 s! g2 |* `- c: u% ]6 ?1 }; V5 S
4.CSS阶梯样式边框- @8 p' \0 r2 i+ Q3 k3 A
CSS代码:2 l* k, [1 ?( L: P) G' Z
#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
} 效果如下:; U% l8 i% s4 ~2 J; P0 j+ D
0 G ]4 V1 `: N; N. {0 I6 W
) A C7 w I( ]9 ^
5.CSS只有阴影边框$ Z3 c( w9 l- M) I/ n
CSS代码:. G- F5 {7 O, B
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
5 r' p; }4 k* B% X+ f
' W, t" A7 k% E2 R: x3 f
( f4 I: N2 U0 g b6 s. ~9 J# ^. N6.CSS带阴影和轮廓的边框
! X4 }0 M4 s9 Q3 r6 @3 {2 TCSS代码:
0 l( i9 X5 M4 ]6 C7 e) b7 e& 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;
} 效果如下:
' f P# \# V4 A( E+ k, m
) O0 ?! L( D0 I
- {3 Q! Y' E) O. X2 A3 K7.CSS少量阴影和轮廓的边框& }& L, O% [ ?1 M, s* a+ l, O6 W
CSS代码:
1 j5 b# _7 k; b* N#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;
} 效果如下:+ `+ x5 V1 \; w0 C$ o% }( z
/ ?% y8 q1 D8 v, ^: i y2 y
" i7 Z/ t* ~6 s# X& @: p5 ]7 t; e
8.CSS带有阴影的双边框, N0 L6 x. ~* M
CSS代码:
0 w! \/ F; f5 }, F6 j% ?#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;
} 效果如下:+ J/ K$ A/ P! Y6 l% Z* D+ Z
" p. T6 }6 I8 n5 C" t2 \4 [
7 [' Q. { U6 a2 T* f) a9.CSS多色边框
3 a# }$ l9 P8 UCSS代码:3 o4 z* w9 ~, X8 `% 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;
} 效果如下:6 k& S; ?- S4 M. [! z9 l
|