CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
5 h6 a* J! j; j& ]; I5 Z 以下各特效用的HTML代码相同:6 m, j3 ^/ v+ D& v$ m' w
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> , B) w7 n( X) n5 Q4 S4 x$ S' j
1. CSS动画边框
9 h2 f: h' I' z* m$ a# QCSS代码:
6 }2 W# z# o' s@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;
} 效果如下:# z+ g8 M& y& Y( D7 B
6 P& o; |- }7 ~: u8 a
5 }, c& [7 e- x& ^: \$ M2. CSS图像边框; R6 A; x4 C& ~- t6 t
CSS代码:
7 n6 d4 L6 a/ S5 M6 b#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;
} 效果如下:) g4 A1 f8 x# Y7 s0 B
! A% O' b. I9 o. W6 Y: y
0 i1 D& W* D2 a' [: W# y3 D
3.CSS蛇式边框
# h8 I% V d6 h4 }( ^, tCSS代码:
3 w2 h5 V2 I0 U/ V5 r#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;
} 效果如下:! p" b! `. M# H. ?& `! X
) T' T% O& e# |4 W8 q# ]- h1 r, Q2 M* c0 i! ^% _6 X
4.CSS阶梯样式边框: ~/ P4 o) V. S* P1 E
CSS代码:
( j; b- H5 T7 f' y2 A#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
} 效果如下:
0 U. `* m+ u* m V
9 }. l1 S& l, h7 X7 G" s" ]6 C% _0 W3 ]' m9 w
5.CSS只有阴影边框% j8 V. M L6 B! W; ~' o: L: m( ^
CSS代码:) U$ o' h, s! C' T
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
, {9 S _- ?' T( R2 O' j
) f5 K3 X$ M& V. c/ _0 S8 j& |( }+ T- X; F8 n! E3 J; c+ c
6.CSS带阴影和轮廓的边框& |3 i/ G& t1 U% ? p: C
CSS代码:+ k+ f5 n1 K" j+ v
#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;
} 效果如下:
" K" O9 h d' e. O; o% p+ M
0 T2 }, s/ u6 v5 a, @
2 G( ]9 B W4 s: d$ Q+ ?) Y7.CSS少量阴影和轮廓的边框
% Z" ^3 U5 a1 `" [: lCSS代码:
3 g: \4 [' t& |* m& i#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;
} 效果如下:
: \' Y! f. l" r& z6 m' Z- {
9 L8 i: a1 i6 w. N3 J2 z. C) R" J
, [% J' y# j7 \3 J8.CSS带有阴影的双边框1 U; }, j& {. e" Z( R
CSS代码:
b) U# h6 E; T: }2 m#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;
} 效果如下:8 s: W3 d3 x6 K
% h9 |+ C6 t* a$ P( j
1 J9 b/ c! ]2 u4 V6 N" ~3 J" C9.CSS多色边框
; d! M5 `) |3 l# F h$ o# lCSS代码:
/ A$ d7 \! M' Q. Q0 Y6 Q#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;
} 效果如下:8 A n; c+ N" z3 R8 Z: F* q! M
|