CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
! ~+ P, \/ J4 `4 A# N2 c' Q# h* N 以下各特效用的HTML代码相同:
/ d$ d( L/ L+ l6 b2 y7 A<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
8 C7 y, w J& R3 k2 r0 [1. CSS动画边框
- G. s+ I/ ?0 z R4 c$ p+ M1 QCSS代码:! i/ M6 y' y" V* }8 W
@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;
} 效果如下:
0 l! H0 K" V& c5 }' S
; b2 N, i* ^, |2 ~! H, M6 g4 F3 @' X
7 Q6 w; w0 K. l2 v# A! s2 K2. CSS图像边框5 ?! T8 k9 q: X/ V$ X1 c
CSS代码:, K3 x z+ [6 n, p7 @& X$ 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;
} 效果如下:
: i9 Z/ C& s6 N) M1 @
$ X/ a1 b6 u4 [; {3 I, ~- d4 y
, ]1 f8 ]- e+ d) m9 C0 R+ r7 I3.CSS蛇式边框
o# i1 a0 s$ m+ PCSS代码:* S) g$ }7 h8 T7 }' c! z: j
#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;
} 效果如下:9 j) P) h/ H) Q, y5 \# J
2 ^' u- @! T# |$ b! p+ z. a
7 H- R$ E3 y1 A4.CSS阶梯样式边框
9 g/ B3 T6 d. ]) u$ K1 `# ]8 SCSS代码:" C# W/ _% t. _
#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
} 效果如下:
: d/ i4 l$ v+ }% l) n* u- c
( x& ?$ U+ L% K
5 `3 M# i% V/ {# ^7 x! }
5.CSS只有阴影边框
( e/ f+ K2 R9 j! A. Y, YCSS代码:
7 J1 b7 r3 k" B5 y, i- C% O3 X#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. }- n9 `/ I" w- d
0 |" O$ e4 j0 d) o% P8 G
$ P! E. v1 u7 u0 Y5 _) W# V" `6.CSS带阴影和轮廓的边框
% d2 ~ i1 i) `$ JCSS代码:
7 B3 w7 A; Y5 n+ `+ i" M#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;
} 效果如下:2 L5 Y& q X2 m& U
: H6 q n- _: c& a4 k9 D4 a1 r
5 b% b9 ^- {$ K( F: H8 G7.CSS少量阴影和轮廓的边框
" G% m$ f' v* Z% s/ u3 gCSS代码:
y; n5 E0 I/ D# f# G2 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;
} 效果如下:0 q3 N$ d2 K n3 n- B% y
, x$ l- C" ~" H9 ^' c8 l2 v; b5 s
8.CSS带有阴影的双边框
3 V7 ?6 w1 @8 z4 Z7 _, q1 BCSS代码:/ N8 l | K. W# |7 V& d
#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;
} 效果如下:
. k4 K% o2 L; \# E& j
2 F" S. j$ ~. s% W: d& A1 h r" T- y9 z' H; G
9.CSS多色边框
0 o+ R# d9 K& x* [9 _CSS代码:2 ], {+ u/ }/ _- ?, V# F# f4 o
#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;
} 效果如下:
! `: }1 A& a: m$ e7 C- v
|