CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
1 X; v4 e. I4 X. P4 w" v 以下各特效用的HTML代码相同:
6 c h' O% Y* Q; A<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
7 Z9 z7 L" j+ V8 m6 J$ A# ^1. CSS动画边框
4 S% S0 T. V" XCSS代码:
9 `2 a2 I: Y1 j I m9 o7 u@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;
} 效果如下:
& S' {% l; }3 d B/ F
& d, y B" W; g$ P' t
. i: O2 g8 Y6 J, t; v& V8 J5 k2. CSS图像边框
3 I0 _/ w+ I5 g& T- rCSS代码:8 y0 T+ l, Z" n
#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;
} 效果如下:8 K, x3 w: R/ y* K7 z! W
+ K' H! d6 a4 Z; I) b
7 ^* O0 n, _4 ~3.CSS蛇式边框2 l. K3 ?& R$ J. C$ r% e4 j- U8 b7 {9 a: r
CSS代码:
7 C9 P, z8 u4 k#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;
} 效果如下:) E$ Y( v$ z. k: [' ?3 k
, {% x+ }& I9 L# c* a. a+ |. f
0 x5 S/ Z b! V7 g4.CSS阶梯样式边框( s' _1 G$ c+ a6 _9 R
CSS代码:
$ i5 O; ]' |) e: L8 t9 `#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 Y" @/ z0 x6 Y5 f0 H
9 ^/ f# M! U0 S4 _9 R& u: H2 T0 o' Q1 j# b* O8 l
5.CSS只有阴影边框0 B( @1 u h) O0 r0 t4 }9 g
CSS代码:$ \4 g7 @, b- e p B/ s# y l
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
- u- W* [ B' E
: t1 r, [% p- i0 k6 x6 Z
# l0 E) Y* V2 r6 ~+ x6.CSS带阴影和轮廓的边框
$ c \* R( Y6 L8 G9 zCSS代码:& S G8 k; G8 k, p3 f8 Z6 C4 b
#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;
} 效果如下:
) s- h2 X ~' h' z3 [9 y
8 b* Z; x# Z2 @' F& o
# ~6 A( K' W) z
7.CSS少量阴影和轮廓的边框
- N* M- X) {% z1 A- j. Q! xCSS代码:) t* z: f1 a }5 g( ?
#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;
} 效果如下:
1 w. d. ~6 y8 L, D/ L
) J& n( R6 g2 q& L. H4 } m/ b/ x2 Q0 A
8.CSS带有阴影的双边框
# d1 R6 O9 x5 z8 h: A! xCSS代码:& H" y7 ~0 W* O8 C! e. A8 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;
} 效果如下:( |1 c9 v& N% C3 z
2 z' ^- J3 {' K6 Q+ b, _
. I- B* `0 ?- i' K* H8 w
9.CSS多色边框
( K9 X5 ?9 [3 n8 pCSS代码:& v1 m5 M" w+ I( M# ]0 v) 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;
} 效果如下:$ P1 o# `) B7 s% P
|