CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。& k- V6 X% m4 A/ H) e
以下各特效用的HTML代码相同:
. @/ O% p" E5 o2 b5 j& k<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
$ M t. k. h; _( h1. CSS动画边框
! i( q6 T5 |- e$ P1 i& pCSS代码:' x8 M3 B" I. K) H1 x) H
@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;
} 效果如下:
+ y2 i$ I# a, v* e5 e" u& R
9 s6 |7 U }3 [# N3 `
m* [! Z! K h- N2. CSS图像边框
6 d& Y8 f- x( K$ y" K1 ~0 r3 BCSS代码:$ b& L; N% B- L8 A* C2 x J
#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;
} 效果如下:# v: s* L: O7 q7 _! h. j
8 L9 I* d" U( B) p9 A
+ d' J4 p/ w. V6 ?6 C3 z& C# F
3.CSS蛇式边框
% V: ]% w4 \, ]+ f' zCSS代码:: N" R$ \9 W/ x" D' o6 @
#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;
} 效果如下:3 }& A/ e( ~; C1 D% j+ A
1 O, ~( U& ~; `2 g) o3 w2 R5 h& k) }0 f6 P
4.CSS阶梯样式边框) N/ O9 y6 N Q# G' ~
CSS代码:6 i2 \# Y* o X7 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
} 效果如下:
1 h9 y9 y- r& ], Z
4 l; W5 y, I" C. A: B! u0 h d" r/ [' y( K! h! n9 V7 X5 z) q
5.CSS只有阴影边框# U% N/ V% w- A: o4 }
CSS代码:
6 ^: k6 m" R1 A) ~& t# w#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 q* m1 [& Q) \' i( ^5 h1 e4 E9 ~
2 c( H" h) h7 [7 |- Q( Q
. o3 [, h2 {) F6 t6.CSS带阴影和轮廓的边框
B* }# L( Y$ a1 TCSS代码:+ @% B( E# v! F H1 I0 N9 R& 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;
} 效果如下:
: J, S1 S- B' |' Y( q5 w
1 T m" I% K% Z3 O6 G* N
/ Z" V/ M* S. V& n+ T4 X7 D9 N( t9 e7.CSS少量阴影和轮廓的边框2 R% Z6 Z* m5 w; P
CSS代码:
, T" S0 F& i! D) f#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;
} 效果如下:# A& g' G/ z5 Y/ R' \
, _+ E1 _0 O$ p/ [, P
. H4 n$ }0 h3 W1 [: b8.CSS带有阴影的双边框- |0 P% c2 M r2 k$ j7 P- I0 h8 G1 \
CSS代码:7 w) \8 s3 h* a, N
#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;
} 效果如下:
8 P9 X9 I+ A$ O
0 @ c: `1 r* m
1 ^9 [9 y& X! c
9.CSS多色边框- ^' Y; R; m$ A" x5 I! F0 a
CSS代码:
+ i$ @$ E% Y& K- A' @" p+ }# m# m#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;
} 效果如下:
( v* @. o0 R2 ]! x
|