CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
2 P5 D% J( F2 D# _ 以下各特效用的HTML代码相同:
( h6 B+ {1 P1 o7 s2 j1 M$ ]<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
( }. P# e; A! e( i% E# g0 [& a6 Q4 ?1. CSS动画边框
' V* W) z: J$ D7 ~% ]5 k1 |, j4 N8 pCSS代码:
4 W* l0 w+ C" G3 T+ t$ H, z@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;
} 效果如下:
" s3 I+ G, w3 C' }2 [, g3 m
0 K* m( D/ Q" F3 @
4 ~, a* h# E. e" g4 o
2. CSS图像边框
0 m' r* W) z o$ g' pCSS代码:. V; d: }, K' l. g& q" L. X2 N
#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;
} 效果如下:! I' [0 [0 V: w. T3 V/ X! _2 W
5 w/ |0 ?# E. H+ }. H+ k* M
, {. F$ _* q5 H4 ^3.CSS蛇式边框
. ~5 x8 O/ D! g4 m' O( F. `0 U' TCSS代码:
1 f) m' e& G) J; F: ?9 w9 N#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;
} 效果如下:7 k7 h) q+ i( Q4 x. c( o
' V+ z" P/ D7 z% `3 b% I
$ q- _- g" ?; s1 I/ h4.CSS阶梯样式边框
9 _' {. ?% K2 r$ m; |. eCSS代码:1 F9 E0 ]6 g3 ]2 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
} 效果如下:
" y8 a8 ~& `4 z3 e" U
" R d' o1 R1 X0 P% {
5 o* }2 G5 a1 p/ x5.CSS只有阴影边框
. Y( M7 L. ~* U3 a9 t; z. W3 TCSS代码:
) J; |6 w5 \- e* ^% c g) f! [#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
: ]4 R; f; p0 {5 |/ P7 m. k
5 ?3 m8 W/ s5 \8 o! w
$ i; _, y1 v! `9 Z6.CSS带阴影和轮廓的边框 j8 x! \5 \# o) p7 q2 [8 w' m& r. u( o
CSS代码:) K. a' ^7 h" E8 e1 ~
#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;
} 效果如下:0 F8 Q' E6 H/ X5 S' [0 A5 ` ~
6 T p: g8 x! |& {! B# j
$ C' e0 H3 X5 E$ C7.CSS少量阴影和轮廓的边框5 m9 p' ]4 w3 h6 z
CSS代码:
% n+ Q: q" i5 C; F#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;
} 效果如下:% `, K7 [: W# t4 A8 a+ |
+ H* b% {: ~" o8 |1 o3 [% s2 Q
7 w s' s- S Y/ b+ j0 m
8.CSS带有阴影的双边框
$ V+ t; o; b4 e! y% eCSS代码:
9 E0 v! n8 a# p, B3 Q" l* C#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;
} 效果如下:
$ k1 L& U4 u: l' C0 P4 B7 m
7 f! _9 o+ M) K% \
* a$ ?. `. I3 y" Q( a
9.CSS多色边框5 w5 z5 _- w7 B4 Z# S2 L' b; d+ W
CSS代码:
+ i9 e: _, `" n; V7 r2 K( }, Z#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;
} 效果如下:# j- W; f _) \( ]) X# | E
|