CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
9 I5 Z5 N' Z! w r* \ 以下各特效用的HTML代码相同:1 s4 N/ h: l n. u0 j0 ^
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 8 ?( H9 X2 }5 ]. K: R4 i" ]
1. CSS动画边框* g* F K( M d+ p' x
CSS代码:
( {% L7 h' f6 |. d3 j( c1 f@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;
} 效果如下:( N: c* ~# d- X& |
* ? S9 x5 s [( x7 G
1 z6 S$ h- d$ E S; L. g0 l; x5 d2. CSS图像边框* v- D0 @+ Q/ y
CSS代码:- ~) O- h$ t/ s7 z! W9 s; S
#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;
} 效果如下:
) \+ t+ \: f8 A2 \- V' N/ q
% D& M8 v. Y5 _
0 g( G$ p3 J y+ C. w' F3.CSS蛇式边框* p+ O* {, m( H; q9 W# Y
CSS代码:
8 @: I5 \9 H9 Q1 Z+ C4 B1 E: C. a#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;
} 效果如下:# D, d, t% v; d
9 ~2 m) S4 N' Y' n( z* r7 ~
$ ~' [8 l# c& R0 J* H/ i4.CSS阶梯样式边框
, M: S, ~' C! G. [4 g. V, \CSS代码:" j9 X2 ]4 o! Y; s2 I$ _. S
#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
} 效果如下:
9 [8 y% m' P+ L
+ v P' e) }5 V4 p4 v
7 v6 i) t4 r) U5.CSS只有阴影边框8 x9 f4 J1 V8 d% W" X2 {
CSS代码:
& g. {# _" G* w3 r#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 D0 ?! K" [8 S% r6 L4 N) {, \" j
. z9 g- I3 S$ A! H0 R( y6 N0 Y8 {5 J2 j( G
6.CSS带阴影和轮廓的边框
1 l/ K# I" U; V2 e& h+ fCSS代码:
( C+ r* i' i$ d y: L#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 x& a; B! N8 `
) N* p4 Z1 v- |, Y& i0 B
: s7 r0 W8 r4 H3 |- ^3 A& o+ m
7.CSS少量阴影和轮廓的边框$ t5 v, Z+ u) X1 R# X, }) N
CSS代码:
' T5 N! B4 g- U7 x& Y- V. d3 F* W#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;
} 效果如下:
. k5 O$ j& |( ~
# G9 u+ |$ A2 D2 M w' B) R4 D& S* f" a2 A/ S
8.CSS带有阴影的双边框
8 C7 k$ ^2 I" a. x G3 P! ^CSS代码:
2 u+ f# B" h, J#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;
} 效果如下:
0 h# K( O( h* R1 \4 Y! O% S, Z o
$ y, o- V- p; l0 H+ m2 @! x" c: T4 F3 |/ |2 p1 a# i
9.CSS多色边框9 l8 x- q4 _( I) D T
CSS代码:
1 h% @$ t. w& u, T+ ?#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;
} 效果如下:; b( H1 B( Q: c6 }) t/ p
|