CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。( X; a7 M0 Z5 ~# B1 V
以下各特效用的HTML代码相同:
3 ]! P# I) v0 z6 L$ ~! ]; ~) O) T. r <div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>% y4 a7 x7 J) e5 C
1. CSS动画边框 & }' D1 a& g% }5 b/ h0 i9 J
CSS代码:
" V7 L5 V6 C/ J5 M+ T1 w6 g @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;
} 效果如下:
. C s* y1 t @/ }9 ?3 v" N5 `0 |& O1 Z
- w2 P& S. s0 u3 `8 {, E, u2 z
& w2 ]. T/ v: p
2. CSS图像边框 , x7 N: j2 x" l9 \
CSS代码:# M$ A3 e1 Z- P. v% J; s4 P
#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;
} 效果如下:
: e- N4 F; a" N/ O* J& K, j5 ^ i
/ |2 @, h2 @. v: k+ O+ F$ I $ j: {, Z) c+ P% L6 c/ Q w( n+ j
3.CSS蛇式边框
! ~9 c$ z3 A6 H9 U8 U& e. h- u CSS代码: i }! a4 h7 S* w. P5 Z$ n! C7 k
#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 G4 c7 s$ e C' T9 o- l
" Y- R# {' \7 t; x+ }
u: F/ J) U" Q: f8 A 4.CSS阶梯样式边框
$ L0 H" @& j% y% E CSS代码:- m7 F; d3 L7 |3 ?0 U
#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
} 效果如下:
; w2 J- K' { G8 E0 k
" B A' G" c4 N2 l7 o+ w
+ G- K( m8 t `# |7 n; c' ^/ v 5.CSS只有阴影边框
7 g# I, }& I } l* i- @! U& m7 Q CSS代码:. W$ p- Z; E/ m+ H/ } u
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:- R6 U0 Q+ ]% F" u6 p
# L% [+ c$ `& H- y4 w4 s
. Z1 Z9 L/ M3 R
6.CSS带阴影和轮廓的边框
( a4 k/ {: }+ c M; } CSS代码:9 T$ g3 {" C: I* K3 E8 l, S3 G0 w
#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;
} 效果如下:
! a9 q) ]6 z! L* s4 n7 y$ g
$ F" Q6 f9 m; J0 r `
7 w" v. I Z5 p1 z4 b: H 7.CSS少量阴影和轮廓的边框 ! X2 e) w& K$ f- _# k) e; J1 c
CSS代码:2 ^+ O, l' t1 s" e8 ^' x6 ?; a4 q
#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;
} 效果如下:! v) W4 M8 A0 j; }: I' T
1 Y# l8 s# H& t9 _
4 q4 X% }! S$ @/ e0 ~ 8.CSS带有阴影的双边框 4 I+ B0 L$ c" \% j. r: }
CSS代码:* |/ `3 i ~) |+ ?2 `: \3 p R
#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;
} 效果如下:
[! X/ K3 B% i: U% c y$ S( u
: E, M, D( ^$ N- d: \- ^, J
( E/ N% o0 ?+ c) V! `" Z. {, u 9.CSS多色边框
) c: c. X. z# P' Q$ C0 p( P5 D6 Y CSS代码:
3 N6 W' [% r( F4 Q2 p #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;
} 效果如下:
[, O+ b$ D8 L% a: D