CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
9 m) L& N% q F4 \* c 以下各特效用的HTML代码相同:
0 i$ o7 ~6 q# V: ^% R! M5 @. v1 n, g<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
2 X" q' [6 _" F U0 t$ @0 c3 X1. CSS动画边框
" a! J" j/ t0 b8 LCSS代码:6 {- q9 C' u( i' f3 I
@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;
} 效果如下:
& }" I3 u$ D! e) H7 i$ X
# x {& j/ c3 E2 v
* x& r5 T8 U1 b0 s. z2. CSS图像边框# l r' L$ a. z2 i0 y
CSS代码:, U2 y" ]; u* ]; 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;
} 效果如下:; j( A* |" L ~1 k1 E5 V
" w" m0 J' r `& z7 ~ @: _0 _! i4 R- u7 _. a
3.CSS蛇式边框! m; }7 P6 s6 x2 \
CSS代码:
( F1 Z) X% u( x#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;
} 效果如下:
- x+ n: P2 ~! z+ ]: k
}# N4 _0 j: r7 o0 `4 `2 Q- H; Y+ ]2 m# c: H
4.CSS阶梯样式边框" e2 p5 Z w, v6 z
CSS代码:
; V0 i) h. 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
} 效果如下:
+ y/ s( [8 o6 }% w' a% C. t1 |7 U
9 `8 Y+ i# h- a- \8 z
1 |. N6 V- {3 k& a+ }1 f
5.CSS只有阴影边框
" U, H2 |5 n7 NCSS代码:
2 z. C) W5 S* O7 k/ r9 o+ z0 c \#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
' N9 i* g/ V8 H% B, z7 o
/ Q: p, f8 h. {0 L" X6 @! u! N m
/ c& D; e1 q- q8 z! h) u6.CSS带阴影和轮廓的边框
' t: v* h* m5 {" B( ]. F' ACSS代码:/ a5 N* A# W8 q6 n
#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;
} 效果如下:
# Y' J3 _+ {0 R4 v( L5 E2 {2 a$ R3 n
" B- {1 v% ? @2 B
+ L0 y5 |6 J: [3 m5 V& ^+ n. D: q3 V
7.CSS少量阴影和轮廓的边框
- a3 o! p. I. ^( ], c# iCSS代码:1 l/ {% Q9 v) l! V5 w5 H
#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;
} 效果如下:
8 U! n1 @8 J9 ~8 }& n0 E2 [! c1 g
5 {$ i( d4 m0 N! Z9 z
3 d5 t8 [8 ? b8 F/ C$ x: ]8.CSS带有阴影的双边框
% Y* E$ r+ z% H2 S2 b* \CSS代码:
4 L6 l1 ^; I# G8 b5 y4 R1 g#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;
} 效果如下:1 [/ x4 l/ [+ [
! Q6 m. m3 {- ^7 d5 K# [. J7 B N
* @1 F+ z T6 _: N9 Y7 [! Y9.CSS多色边框1 z% G( S& E! _# W( V7 I% R% S5 @
CSS代码:) ] c" P/ R& m6 U. g, B
#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;
} 效果如下:
1 m1 _- f' h- e6 ~7 ~
|