CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
% t$ x" r T2 X- j- j 以下各特效用的HTML代码相同:- }0 G! ^6 a/ ?# w% N
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
3 n8 x$ T" f3 m7 i1. CSS动画边框0 e6 {( h) b8 A( z8 U6 K7 m
CSS代码:
* d- U, n: R3 V; D- [@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;
} 效果如下:
+ a, m4 I; P2 c9 p. r/ M5 E
* R! E5 X4 M& q5 `+ N7 J; a) @# x5 u# A. h4 q" M. m: a
2. CSS图像边框9 v) @2 M" W$ m1 z- u! g
CSS代码:
1 i% u- [' k8 Y& ^" T#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+ ^& p0 D! @& d& D
$ s; e$ X& `% { O5 H- U
- z! ~& N; r# y/ n+ S/ v: \
3.CSS蛇式边框
% c; K- t' b. {5 z5 r. WCSS代码:
' M8 w; V" E5 ?1 {* x- N* O* t5 V#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;
} 效果如下:$ Q: f# ^ D7 n6 L
9 \5 g+ t3 J8 S* z
! P& s( x- a+ Z5 W- ]
4.CSS阶梯样式边框
' `5 K' P/ X+ t2 B7 R; MCSS代码:
$ {) K( K9 Q' Z; c# k- a* 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
} 效果如下:. d' ]: @3 T( ]2 q2 }# f3 C1 y
3 K4 u' R+ \3 p0 G. G: X c f" l
+ B& `7 a% }- H# H( L( }5.CSS只有阴影边框3 O; ?8 M& K! {( }" Q5 ~$ A
CSS代码:4 n _5 |" m, N. E+ A5 V4 F, j- y
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:' Y0 h5 q; w! F2 Y; k: R
) M! {1 S, g3 K5 [8 Z" P8 _/ W5 G
4 S" |" S0 H& }6.CSS带阴影和轮廓的边框& n! z+ M5 }0 w9 B& `% Y
CSS代码:2 G; E4 J7 D# v% 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;
} 效果如下:" M4 ^5 ~; b/ b8 ]9 e
0 ?- V' ]2 d5 g" a3 _# b ^4 f1 A( N/ A c; r
7.CSS少量阴影和轮廓的边框
: l+ |/ J4 Q9 @6 `CSS代码:
9 y! w# m* D8 P4 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;
} 效果如下:
) T0 g: [$ b* j: F9 Z. S
# F+ b- u3 d$ Z6 G' _
2 G2 m$ {4 v, V- f. N9 m# i
8.CSS带有阴影的双边框
0 @2 u0 O7 A3 T8 N% xCSS代码:- ^2 B0 t! c6 q( Q4 h/ {
#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;
} 效果如下:
: Q" Q/ ]7 `! s# J8 }- t# w
" s L |" N; Y+ P
, T/ B- n; r8 w, u9.CSS多色边框
- h) n3 `0 H8 ]4 ~CSS代码:
q }. B8 o' A#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;
} 效果如下:4 [0 x' W8 b+ I/ ^
|