CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。. h U3 N% ]2 K! w0 q( E
以下各特效用的HTML代码相同:# f4 F L$ C' ~' U0 l, s) d3 `: Q& u
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
& d5 w& X0 S! A6 [9 ]$ K5 B$ h1. CSS动画边框7 {3 r( E) c6 {7 Z0 d
CSS代码:
# `% t5 Q9 o! }' b@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;
} 效果如下:
- c1 [5 I+ L- ]9 }
$ f" v3 i; z: w2 A' t J) i! f! Y9 K( C6 g
2. CSS图像边框1 @# B6 D- \: k/ ~
CSS代码:0 I. J. b% \/ d `6 }
#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;
} 效果如下:
! M W D( s; u
) d7 R4 V4 I# o5 y0 Q2 Z: z0 W+ z2 ?; V5 `
3.CSS蛇式边框6 o7 j7 ~# c4 o. O
CSS代码:
4 ^, I, N8 p4 h; N5 [1 I1 @#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;
} 效果如下:
" l) @& W; Y$ `* D+ K7 t
9 t# j) E7 H. V5 A% E/ y7 `5 c
: m1 O4 f$ Y4 F( R4.CSS阶梯样式边框& |; {5 ~2 @) _% z
CSS代码:3 {$ P# @4 B; A: K @4 G& h
#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
} 效果如下:: ~& ?% N; C5 j4 O
1 j2 x7 A3 d) k4 `
. v! ^0 i0 x% {; B* h. U8 {7 B( [5.CSS只有阴影边框+ t; X5 N7 J$ o1 p, S4 r# @; A
CSS代码:
4 H3 ~7 f% S' R- v0 ], g#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:3 ^8 V% j7 ]/ K6 k H
5 `+ \& G$ F! H( [3 q# l0 @9 w7 u6 K8 D5 {
6.CSS带阴影和轮廓的边框
0 \$ m* G9 ]2 S. oCSS代码:7 |4 J# u2 O5 v! _
#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;
} 效果如下:1 d# M; L8 x1 h) Z( F
2 ?2 }( l8 c# ^. v9 d- u& `( R
) u& @3 [3 Y4 W4 B$ p* X5 i/ i6 c7.CSS少量阴影和轮廓的边框
2 L3 P$ X4 |# C9 kCSS代码:
2 t/ y& [& p( l! m/ 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;
} 效果如下:
: {# X \% v; {5 C. z
: p+ E4 E, I Z
: K9 s% H; F5 s6 g K% d
8.CSS带有阴影的双边框
, ~5 }; ?" `8 W; S, v# ^& @CSS代码:1 J9 T# e3 i5 g; `, e! M. b+ U- k
#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;
} 效果如下:( Z$ K$ y% ?1 n' }9 C" S) X3 j
/ W, z5 P8 I- E% U' E
1 r( U2 f2 B2 P2 N
9.CSS多色边框
3 r6 V% Y& A# C6 @: BCSS代码:' h3 @& {- w" p! Z" h
#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;
} 效果如下:( i* Q; a8 ~% ~' W$ n& i7 a
|