CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
3 Z" X7 e6 x. s0 j, | 以下各特效用的HTML代码相同:. L4 R: A, n1 ]4 `
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> - H, j6 R; \8 G, D! P
1. CSS动画边框+ ^( Q( l3 I8 a9 l5 O
CSS代码:. Z7 A% c. U( m3 J5 S/ 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;
} 效果如下:" z3 [ k2 ]6 T/ c$ F0 V' }
) ?0 a# e% ?3 {; { z& }. x9 h/ A8 `6 G& I9 V5 x' E
2. CSS图像边框
, F/ B& J4 N5 PCSS代码:
/ \4 B0 }2 L2 [; A0 ?$ `3 f5 O#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;
} 效果如下:
# L! ~# Z+ G7 v! ^. ?5 a% \
- D( G9 X+ D8 s+ ]1 J- O
# B9 q! ~: [; K8 k
3.CSS蛇式边框9 J3 I% p2 N2 S4 g3 I9 B1 K1 x- p
CSS代码:0 _+ E! i6 `: Q
#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;
} 效果如下:
4 n8 p) S* {9 F* l% P
1 _. S4 h) q# h, e1 C3 {+ k# @1 M, F
# n/ _ p: ?% K, ^' \& T- ]2 ?: S' R- q
4.CSS阶梯样式边框$ z: m% i0 n! j. I+ H/ a0 p% d) R0 r
CSS代码:3 j8 Z2 H# d" T6 [
#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
} 效果如下:7 f' \$ S8 \( F/ q3 Z1 R0 z
. a4 b8 I/ e+ @) t+ O
|3 G6 ]; h2 ~4 K1 g& X5.CSS只有阴影边框
; c2 X* v+ J9 A0 k; JCSS代码:3 L8 l5 n4 i: C$ 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;
} 效果如下:# ~, B# o, \0 m# u
9 b# H8 \% N0 C2 v. K
0 Z0 h% r( O, T- |6.CSS带阴影和轮廓的边框
1 H; I/ @8 U4 Y0 PCSS代码:5 N' s% l, q1 k' e1 ? v+ K
#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;
} 效果如下:
1 G0 {6 y+ i5 o/ D
' j" q/ R) t# g: @ ?
4 r7 ]2 D. }# l9 o. d- H) ^5 I7.CSS少量阴影和轮廓的边框
5 K9 k0 X4 A0 YCSS代码:
+ v5 o( |* a5 L$ H Y8 |#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;
} 效果如下:
. q: ?. a# }. c. t4 t- R
6 b) F! K) S/ A1 e2 e
6 U" t& t1 s! [& W% [5 P8.CSS带有阴影的双边框4 Z* s3 s2 U! m
CSS代码:
7 |0 f' p0 q8 s% 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;
} 效果如下:1 ?' M$ i% ]- F) J1 [! @' ~1 Y
* A3 D. h- f k) V1 [
) h: R0 k9 }$ I) N) C9.CSS多色边框
% T8 y7 Z) U7 c# G3 c0 |, _CSS代码: [* I5 q) \* F5 J8 A8 E
#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;
} 效果如下:
: z8 T( m0 B% a
|