CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
- q% ]* ?0 @+ i 以下各特效用的HTML代码相同:
4 w ~- [; a* r. u4 ~' c<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> - Q( ?( c& p) Z2 J3 P3 h
1. CSS动画边框- ^9 g" `" `% a
CSS代码:
6 U) J K Q* b0 j@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;
} 效果如下:
' m- Y& b/ l8 ?$ X* b) x$ R4 @5 i
9 F9 x2 ~0 T7 x4 g
9 p. \6 s" g& Y% M4 R( O8 F
2. CSS图像边框
! v( L& ]1 m1 T4 G" c, N# v* oCSS代码:
- M G2 a5 V/ B: {9 l& `) @3 c#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;
} 效果如下:
) t6 N- R [0 D% m
/ w7 i4 V5 x# p. B; z3 c' L. W1 E i) w
- v3 W& j1 s/ a8 B; K- c3.CSS蛇式边框& z, l, R- L' i2 l: t9 N: h
CSS代码:
1 G' g- U6 [/ C#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;
} 效果如下:! V) e6 E% P' _
' f$ I% j+ d6 {2 m3 F% ^ S6 j
, q2 j! T: U! H" S4.CSS阶梯样式边框8 v; s$ B# ^; `+ m# k! t
CSS代码:5 T5 M; b/ O; M
#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
} 效果如下:' C! b1 y2 V: t/ f4 O* z; m2 |0 J
# @* f" _! c) v! I- W0 n
2 y, ^, |! q! U+ L& U& T5.CSS只有阴影边框# t# \) o& ~3 K2 U
CSS代码:
* b, d' h3 C3 j. K& d#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 [& Z5 A( c l( W& D8 y
7 `' N' o# ]1 n' B& e
4 q H* R# N" S. h( [6.CSS带阴影和轮廓的边框- P0 a5 f D& K/ j
CSS代码:
8 v6 W- k. |3 t3 i! q" F. P#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& _) N& W/ q3 e: z
! }& C0 I* @! I$ o* x/ ?$ p/ t2 X1 O) g5 V# O2 P
7.CSS少量阴影和轮廓的边框1 x: j; Y1 B6 J- K+ `0 d2 I4 Q
CSS代码:
. q; u0 h0 g0 C6 m# D#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;
} 效果如下:
; r* t9 R! h' V6 a+ ^1 ~7 h
& L4 m$ N6 h/ Q/ w7 J0 `5 K% E+ D( J' n
8.CSS带有阴影的双边框
" t3 [) O4 T# L9 j3 ]CSS代码:
|) f0 C1 v) [4 R" h#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;
} 效果如下:
' q7 a G3 L! ?9 P7 Q& J0 h. y2 P
/ H2 V+ d8 G# v' d- Z0 w. p; Z. X8 b3 c! @
, Y2 p4 h+ k N& ^- i9.CSS多色边框2 T9 i: S3 f) P: r8 J" { V6 f2 l
CSS代码:) p8 I$ s& h! {$ t3 Z* h& j2 e+ b
#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;
} 效果如下:
; X* M7 j8 a) r6 b
|