CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
2 F5 u% b" ~* Y( P 以下各特效用的HTML代码相同:# h8 W; C9 ]) h) S7 b: R J! P6 g
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
0 }$ w. k9 S6 ^' z% K/ B1. CSS动画边框
+ ~: E8 H0 t2 G$ [* [9 c* b$ hCSS代码:8 D) A' A' Y 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;
} 效果如下:& ]1 ~. h) U* X4 k8 N
# i) P: h/ l8 @: I6 P* ?
4 X" C6 l; s& m
2. CSS图像边框
0 T2 s3 F. P7 c. ^CSS代码:( G# }! j2 c7 Z+ q+ ]
#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 e+ U: f2 z! }* {+ {& T, N7 A
8 j: R& f! s: ^- s e7 e6 d# Q9 H; w) f6 V& h' {' M
3.CSS蛇式边框( {3 w; |# u$ r. d! Z) _% L3 w
CSS代码:* p/ {; [6 P- n* f) r9 `5 f
#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;
} 效果如下:
9 e1 Q. `4 k3 k( k
# q0 `$ `; Y$ Q- G* O
6 }+ B5 _8 ]3 ^4.CSS阶梯样式边框& y6 g! `1 Q* b# \
CSS代码:7 E8 N3 ` ]- H2 q
#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
} 效果如下:
0 [5 _2 F: x6 k4 B) \/ ~
- }; t/ P u: Q
6 ]7 X+ K, {- e; n! c% [
5.CSS只有阴影边框6 Y; @& E' P# }4 J: p9 @3 G5 c
CSS代码:
1 M0 a" e! l2 O+ t4 Q#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:7 B; A; p4 ]$ j& V
- b+ x4 ~# b1 P, v9 y5 }3 L. K& N$ a
$ G% ^" M. d& S, F6.CSS带阴影和轮廓的边框
& G( {# l! G. X2 pCSS代码: E' n3 I s& z6 O' R
#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 c- f$ {4 ]: q9 |
# u% h5 `/ n$ `3 e, u/ G! n2 ]6 W) @
7.CSS少量阴影和轮廓的边框
+ K, V& h- L7 q! e, D/ }2 I, ZCSS代码:# } O+ F( Y- @9 ?, i- o6 m
#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;
} 效果如下:& g9 V$ o6 {7 c S# A/ r9 e
: f+ [* H. p* W
' H- Q" \. H) ]6 F* c/ y( C8.CSS带有阴影的双边框; o: U# e' t& Q) K7 n# E
CSS代码:6 g5 k# y2 l/ N6 U# y0 i- J4 p
#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;
} 效果如下:
$ b& z8 d+ M2 s- c- |1 G
$ m$ J; J! ?3 s1 }- Q
; a% Z5 L% _; d' [. V& D x9.CSS多色边框6 q. Y; R" L1 z! J; H
CSS代码:
: o. a+ i6 h; \5 m- e* q3 |0 \ l#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;
} 效果如下:0 C" B( B6 X0 ^
|