CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
9 \/ S: X8 e( [" G! d8 t# X 以下各特效用的HTML代码相同:
: O4 a3 a5 N& N+ z! ?9 I( L<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 3 P4 p( a+ v/ g* Z2 e" B" k9 u x
1. CSS动画边框
; b) C1 |# ^; j$ V Z( `* o. rCSS代码:* ~3 ~8 d {- K1 G. M8 H/ N
@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;
} 效果如下:' ^+ ?) F- i: `* ?) E" v
8 t9 C& r7 u' T2 s
6 d$ k: z: r% v2 ~5 K, G2. CSS图像边框% ^+ Q. R2 H/ E. N0 ?
CSS代码:6 d# C0 X0 P9 p0 c6 ?% Y
#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;
} 效果如下: P( [& H& Z. L# m5 S0 R9 ?1 S
' {2 h: h3 g* P5 ? }. H7 E' ~9 H+ i" v3 O4 p
3.CSS蛇式边框
/ u f. z$ e2 D! {* TCSS代码:
% ^- c" a( E" Z3 t- u" w- 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;
} 效果如下:
8 v7 v$ h" o* O+ M0 O
0 h* V) b4 d6 g: n: E
9 o9 b! H& a* ~4 J- A& |; g. e4.CSS阶梯样式边框" r: }" }& ^! c: M/ F7 U* t
CSS代码:+ g- U7 p/ w0 p# g6 L5 K
#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
} 效果如下:
C9 B+ P1 @8 s. _' ? D
" w; t& p( h- G2 d& |6 _4 l+ U1 T/ w* d' y ~# V+ ?
5.CSS只有阴影边框 Y$ h% r. B. e
CSS代码:
5 V# F; X6 L. }! {/ U8 ?& y, B#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
1 X* i! Z! \4 O8 _" I. A( u
. m! r. e% H- ~ t; Z4 ] Y o
! g, I0 I0 S( k. u$ |5 W! c6.CSS带阴影和轮廓的边框+ o; u3 A5 n+ L
CSS代码:
+ H$ t! J3 h+ _) t2 T$ B" f#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;
} 效果如下:
+ @8 s7 E: i3 B# }
0 R* x% p3 `& N) s( U1 c, a
8 a( U8 `$ \7 l, x9 l7.CSS少量阴影和轮廓的边框
E+ D& y6 F9 R' y! e5 r2 ]CSS代码:
( I- V# ^: l' ~3 t. @+ ~. V#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;
} 效果如下:6 O' [5 e# g2 ?' s
/ S4 H4 F# |; H' _9 G" P' L; H9 c' _9 t# v7 h
8.CSS带有阴影的双边框- |+ y7 N0 T) ^& h* b( Q
CSS代码:4 V, E% F9 h; k7 `) s! W1 F
#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;
} 效果如下:5 j9 W9 K0 ?) _- P
" Y3 U2 C9 i4 J8 E
- K6 X% e$ D' i: d8 Q& H9.CSS多色边框, t- O% i1 T: I* a0 M0 y u b+ e
CSS代码:
, v0 r# d3 b' q8 I3 n, G4 y#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 z) S& k r* T7 Z9 H
|