CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
& J/ e9 C$ Q- e2 ^3 J7 Z 以下各特效用的HTML代码相同:
: _2 |1 c5 ]# h( \7 f0 ]<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 3 [1 E6 k: i5 f! E7 D7 C" o
1. CSS动画边框% n) o. B6 d0 S. P* z* ^
CSS代码:
/ m8 ]# S& e/ M" V@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;
} 效果如下:
4 x6 K( I2 o0 _& {1 W: H3 z
4 q" D+ p* p5 B9 i4 U7 C2 ?+ P+ P" s" \ m$ t( |6 p
2. CSS图像边框4 [" y1 H8 \* c* \ L% F
CSS代码:' w1 u; E, }" j& |
#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 l E0 D. T$ `9 f
( k7 e8 |2 _" g" r
# O# P$ N" ]1 b3 ~7 z
3.CSS蛇式边框
; \5 A/ K' Z5 [1 o, ~1 p* hCSS代码:
8 b# z& B1 V* i- ]8 w5 y#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;
} 效果如下:
2 m/ m4 q. J4 R; ^% O7 h
) E$ X$ v: ?6 _+ e) k
# R' s. t8 R" H5 \7 x6 @# A- t
4.CSS阶梯样式边框
$ v( a# ]3 r9 X* w* \4 rCSS代码:. K+ U( k3 _1 k6 L d6 }6 x
#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
} 效果如下:. ^& W# S1 @( D4 H* m; P
, [* e$ W, n0 u; e. ^. X9 g% n
+ n+ @! q4 J+ \7 q5.CSS只有阴影边框
) T. }# N. R% j2 xCSS代码:1 d1 x* ?. \' |$ G7 p6 o" O; y1 S
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:% p: T5 A G6 L3 R1 \5 z) S9 z
! x' H& D4 p" s0 L
* A% E5 `2 u8 y6.CSS带阴影和轮廓的边框
- z1 x! I) P+ M8 ]# {9 F$ ACSS代码:, F$ {$ |. o. k9 }( D9 g8 m
#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;
} 效果如下:
: @- O* n- V: ] }
" @- v5 a6 J& O! C/ h1 M2 u [
5 J2 Y4 L8 \. W- X W) m
7.CSS少量阴影和轮廓的边框/ l. f: H2 j& O. F, {; R* l2 V4 ]3 K
CSS代码:6 V" b }; O* V0 m$ F* P, 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;
} 效果如下:
3 g' i$ S- d( Y2 _; w0 ]
8 L5 x# D0 P+ `0 P5 b
+ @6 v& @! v$ i& _8.CSS带有阴影的双边框
4 U( J- U2 a% J, O+ }CSS代码:1 J8 y& n% b3 u( W# r* 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;
} 效果如下:/ b, ]* H$ C3 Y; K& B
3 G) t" X1 Z% V1 |. i/ s, n1 Q0 j* Y! ^: e4 q
9.CSS多色边框" W0 r0 @! K! X# \ |% B+ a
CSS代码:
( _. \1 Z ^9 @. E1 A. r( j#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;
} 效果如下:: l8 s' }$ d' ~/ u" ^: N
|