CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。. n8 c* r2 A y2 t$ z
以下各特效用的HTML代码相同:
7 h0 B" {" H/ P, ?, k; z<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> ; t6 ^: O8 X7 I
1. CSS动画边框
6 K9 m. i o1 E- t/ mCSS代码:
' ^! F, I. l+ J* A@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;
} 效果如下:
( F# E o+ Q& k
) p3 N, \/ r& Q! I( j( B S% y# B
( F( F3 D! ~5 _. @7 \6 b2. CSS图像边框0 f7 J$ A5 c5 | ^
CSS代码:8 g8 m( Z! W9 o) h* _
#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;
} 效果如下:1 v( F, k1 K+ K. X2 ]' o
1 Z# c0 h; t" v) D2 z" N& |8 k! j9 r, E8 r
3.CSS蛇式边框# d) p E8 N& h/ v0 X2 T$ h1 ~
CSS代码:$ Y1 h0 p9 }# H
#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;
} 效果如下:) C8 k2 d, q' \# \+ `8 b. Q
$ P# m5 q8 I) b8 h: l# a! Y
: e1 ^+ x" `: a+ f8 H
4.CSS阶梯样式边框. J4 P/ u1 O' C8 x0 R3 B! Q: q$ [: m
CSS代码:
9 u3 E- g7 c6 E$ a& Y8 i h#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
} 效果如下:
6 {6 g' p$ l5 Q8 r2 f& C
. N2 c; c7 e5 e1 w/ z' d5 t* j3 J0 `! V7 B# l6 T
5.CSS只有阴影边框
+ z! r( d: B: z1 g# e: CCSS代码:
0 t% C( i4 H3 h* J+ R, p% g( Y#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
2 v& z+ q7 A. W' z; H
; |# r2 O6 X- e
# J' I1 e0 }, G4 d& X% G3 ?
6.CSS带阴影和轮廓的边框
6 G) l+ G" ]3 q7 a2 yCSS代码:
. X$ S$ ^/ {2 Z. o/ n& P5 q) 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;
} 效果如下:* C9 A1 ~; v4 I
! y( b$ V3 g6 s( `6 n# u. E
6 L" o5 ?% D Q# p) r5 e
7.CSS少量阴影和轮廓的边框
9 C9 `, O" Z1 V Q5 x/ ], t9 j- pCSS代码:
. W! I+ \" Z* B0 h#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;
} 效果如下:
* l/ b# n+ w8 p6 h4 l0 W) d3 u
6 T5 {* s. O" S/ l- [2 z0 h" {
8 n$ v; P/ c7 J/ l+ h/ J; v# V
8.CSS带有阴影的双边框" B0 \! L: f& P' [+ T: R3 V# x
CSS代码:0 c8 l) C8 L( ]5 R& w
#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;
} 效果如下:
$ y" c! V2 m, _! v1 Y
: Z% P* z6 Z8 V8 L! j( U+ k y
6 E. ` D# k, b' s7 @3 K( W9.CSS多色边框
" G7 V; ]9 O! G. T/ V! i- ^2 `CSS代码:1 O* f6 H/ [/ A. y+ r% G
#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; o; D+ K4 d" b8 k
|