CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
* q H& w+ ]" p. t0 k R* f7 @ 以下各特效用的HTML代码相同:
+ M6 d/ g2 }( L2 ~<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> . y3 e# R4 e, g. B* X- @2 J. \
1. CSS动画边框
3 e) k4 P0 m4 }/ ^CSS代码:5 C/ n0 ~! f/ i# U* m4 M' X& [" b
@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;
} 效果如下:* l3 f& b8 n- H7 z+ D3 o
+ W" `2 I- a1 {5 p
. S* t- X+ ~3 H2 n2 O
2. CSS图像边框4 ^1 u2 m) Z) ]5 j# _& Y2 D
CSS代码:
6 L7 ?+ ^' c" g$ T) I% L#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;
} 效果如下:
) T4 |0 C$ z' Q# t0 N% U
+ ^( I8 y: g3 Q5 k/ j9 p0 |+ ]( x! J; t) R* @/ n
3.CSS蛇式边框
8 ^4 k7 P5 y! `) J; WCSS代码:0 t& Y# \3 Y6 ]3 W: l3 N) Y* c
#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;
} 效果如下:
( S) ^. G* r- S5 O- X3 S f
) X4 ] P# E5 U0 T. l1 ] n6 E! r Q# x! G
4.CSS阶梯样式边框
& C# V0 E; m5 T+ J, ECSS代码:
- m, R6 m$ b0 w. o6 j) A#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
} 效果如下:
2 _5 t! s: h$ @2 r: l7 U
. U$ @8 a+ |+ F1 S t) e
3 M& q+ W: u. m) y2 g/ o1 ]7 v7 L5.CSS只有阴影边框
2 F) q. D; | w& i7 S) D3 H2 {! I9 i1 ICSS代码:
; N+ ^" i7 i8 w; ?9 N#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
) Q% X v, B1 s5 G
: C" N8 G7 [% h/ U! x e* x) V* G
8 Z& g9 @/ M% I' A6.CSS带阴影和轮廓的边框
[* l4 [) ?7 r- @2 |CSS代码:
1 W7 H! x* Z$ c. z' n! E7 g#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;
} 效果如下:* J- _ f( V3 [* X3 z
3 m* h S! W o$ n' ?" b* b9 J5 s4 m. s+ i% Q+ X& w
7.CSS少量阴影和轮廓的边框
- `2 F- b- z) N5 E+ k9 DCSS代码:
. {: V1 D/ M G, g#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;
} 效果如下:
+ J1 r# S0 I4 S( l( F) G1 O
0 N' i E* }% X) T3 X+ S5 b
+ `# j2 W v0 M% f8.CSS带有阴影的双边框0 l2 w8 Z: ^$ T$ k
CSS代码:
5 x" f' w: W; P7 P) [6 g& 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;
} 效果如下:3 [" |, y: S" @! \
9 Q7 Y2 L" v+ a/ C1 i5 f' o k
1 Y; Q* u/ u5 u* J9.CSS多色边框
' S( @. w* Z8 j# E4 [+ h2 {CSS代码:
9 }$ U8 p' m" e#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;
} 效果如下:
$ W {& i4 O+ G5 ?5 ?( W8 W
|