CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
* ?; P0 z. [$ C3 o 以下各特效用的HTML代码相同:
, g6 w }5 H5 P# V8 [4 R<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
) y O# |% u9 i3 |1. CSS动画边框, L2 t! f) f& g
CSS代码:8 o' V* u2 F$ C
@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 V" o" l' ?7 s% A( X2 C
5 B. j4 X6 b# r0 v$ C6 F/ u
" U" }1 [; s' O. j; i9 {0 Z0 T2. CSS图像边框
4 h+ p; T( s% |8 ]& BCSS代码:
0 |0 ?4 k7 a4 Q: h+ N8 \1 K$ o#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;
} 效果如下:# B+ q% q E- W1 u' T
8 m; s0 X: z9 p" S
& }- z0 h( p: c* B% ]( R/ t
3.CSS蛇式边框7 b% C; j4 |( ]* ?( c6 Q' D7 U
CSS代码:
4 t7 x$ [( A# F& g#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;
} 效果如下:
J. e8 p, W& Q6 E
% ]' S7 d& U D% q( U5 L
& A4 @" X* e A4.CSS阶梯样式边框
, F1 ?7 q/ O1 q9 ~+ S( J$ GCSS代码:
$ G9 {2 f8 }; G S" h6 f#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
} 效果如下:4 m( t2 S) I8 j' y+ ~1 W- J2 s) @6 }
+ c" q# e9 q4 }2 `+ T8 m1 L1 [9 J; L# L
5.CSS只有阴影边框6 l2 c6 }& n/ \' ?% E4 A1 g
CSS代码:/ ]* U) k0 W# H, ~/ N) f
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
) v: v2 y0 z' ]
( ]* g1 d& s: g
0 P2 V! x. H9 q) |& n% Q# X6.CSS带阴影和轮廓的边框
: g1 B4 R5 z. n; ICSS代码:3 A8 O6 x# u( E
#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 Q; x9 F5 X- U- i, _) s
- D$ u. J1 }! a9 X
( B4 L: C0 j4 K+ o7.CSS少量阴影和轮廓的边框1 A- G8 L' D/ G; u; z. k! `! V
CSS代码:
' @, C# c5 _# ~ [* c& V) 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;
} 效果如下:
. h8 H$ D6 M5 o% Y9 Y3 _3 \
: ~3 H* ]) Y$ o' O, ?7 J
) |4 O1 b9 t- U
8.CSS带有阴影的双边框
9 @7 J6 P- \- t4 l3 k/ L# }CSS代码:
6 b0 Q) d( s/ f4 K1 s* M# ^#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;
} 效果如下:
$ s( J6 W3 w; N6 ?
: S0 \: q, X9 j6 T8 d+ J* K
" R- m9 W$ K3 H+ q9.CSS多色边框& H* y7 l0 d0 ?
CSS代码:- i% s# \) M# ~5 u" ~" _
#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;
} 效果如下:9 ^$ y$ i- E; l0 ]; l; A, L
|