CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。# }/ L9 ^2 O$ S1 v
以下各特效用的HTML代码相同:" n( O1 a: P6 r4 t" B6 p
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
- B- f0 A* O8 {7 h' D6 M1. CSS动画边框1 |$ J0 w' t' p' W, f+ ^% Q
CSS代码:
) ?3 w3 U& C- `+ t@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;
} 效果如下:
* D) P5 J; a( A
9 c: F: T E& B. B& a- k
. f7 [( p; x) f' W3 f
2. CSS图像边框
* u" c8 \* ]+ |$ s! X" ~! fCSS代码:
- v% _: d# d1 _- T! k/ Z, A# Z#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;
} 效果如下:
~8 m5 p- ~/ s- n
* K" Q8 m; W% R+ Q2 Q. n+ x
" E+ V# G2 r! I; Z' V
3.CSS蛇式边框0 ], W) M% b8 X& l H( o0 A
CSS代码:
3 H0 {+ w7 t8 ^: x# 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;
} 效果如下:
$ b- N, \6 y# t% h; L5 K
8 U* d9 H# ~0 l) [& \$ G6 R5 g0 w6 Y) ^! ~" a! j# I
4.CSS阶梯样式边框5 `0 K1 H- i5 p$ U2 j
CSS代码:
% s4 Q9 U+ [3 `#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
} 效果如下:
* r+ e, ]- p+ q0 U# J
1 O! c' D4 q( A9 W2 m
! x; a& L# Q; V D+ v7 _' ~! J" w; y& L5.CSS只有阴影边框
! M/ w: t" L" W9 tCSS代码:* C# r3 _! A! b1 X* I% W' G
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:5 c6 n3 y# r6 c C. ^- K1 S
- U/ W& T% s( b; e) Q% k+ W* J1 j' ~% I
6.CSS带阴影和轮廓的边框: V- j, `# v3 |# O* w) M
CSS代码:
2 T2 l, S9 E& y' u#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;
} 效果如下:& r5 n' |+ S3 f. s# l
5 n! P0 w0 ?5 @4 k
( S4 ?8 j& Q! L) y+ u7.CSS少量阴影和轮廓的边框* M* {' A' v+ u% o
CSS代码: [, g. S( F- {1 K# W2 [0 z
#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;
} 效果如下:
" t& t, Y& `$ x$ [2 N* S
, h' A7 \5 v% y s$ G9 O, m2 G+ T
: ~# o; g3 B" z( [1 w; r& ?* f. [( N8.CSS带有阴影的双边框
" P( D8 l) m1 t2 C4 uCSS代码:7 |: M/ V1 V0 E9 Q+ z2 y
#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;
} 效果如下:
6 q' S% N' n, r2 R* ~! Y
3 f, s) b9 B5 T
/ o6 \4 n3 s- s( e) L8 n9.CSS多色边框
+ N6 E" G* h8 l. h+ w' l: v3 fCSS代码:8 Z8 p G! r% ]4 }. p3 o) k
#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;
} 效果如下:: p0 j' i9 Q5 B% C9 S9 G, Q
|