CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。' ^4 e: C( U# Q/ b$ [
以下各特效用的HTML代码相同:( G a% h0 L5 X3 S. v# c/ s
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> + I* ]6 m) V0 M: A$ i5 y
1. CSS动画边框
/ K5 W8 @6 [( j. {) O& FCSS代码:. R" s0 N' R# s- t4 V1 ]
@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;
} 效果如下:' y% g2 t4 h4 m' V( Y8 y4 S( f
. s5 R% S2 z# R4 P2 t5 E2 o2 |
7 U" M K9 X( m9 N7 r9 z2. CSS图像边框4 A3 @! f5 h3 M2 h, K% {
CSS代码:
! L' {+ h! O9 n @& N1 k- D; P#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;
} 效果如下: E: M2 |- r$ M2 |* A5 \
* Y/ V7 q- K8 T7 i
: X6 F) Z+ i0 x* c3 p
3.CSS蛇式边框4 ^' f% A+ l7 W& l5 i* S: A2 d
CSS代码:1 O3 g4 K1 h9 g9 U9 T% e
#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;
} 效果如下:
6 d. N( l$ F% E2 w- z5 l) _
/ ]: I4 H* O( j. [5 b# L/ m9 ]
2 D1 q5 w" V0 q" ~1 m7 e
4.CSS阶梯样式边框- O. r3 _% C# R( _* z
CSS代码:) X* E! O- O4 v% `4 U* W" n) g* p1 G/ C3 n
#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
} 效果如下:
4 A8 j7 _! S$ B2 u
8 b% r; N9 K) a1 ?# u
7 T! k% Q) p# d" q W) T5.CSS只有阴影边框
' j5 H( n" d+ i. H1 LCSS代码:5 i2 b1 \" U* n) D: P" }
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
0 C& g" d1 f( _8 T1 w7 s
- l& h7 t( S6 E9 G: Y
1 F0 P! }3 O4 k# _; x7 U. J6.CSS带阴影和轮廓的边框
4 s p/ J" h3 m+ O! w) h0 Q5 iCSS代码:
0 b# }; n" e3 E, n% 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;
} 效果如下:4 w3 O! g5 @, H! v
- }6 ?3 q; r Y( V+ X( h. Q8 C0 F0 g! _
7.CSS少量阴影和轮廓的边框- W7 w/ d& z: B; E
CSS代码:
" \$ f" ?4 k8 w8 Y. O& |0 F$ 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;
} 效果如下:6 {5 b$ L! j8 v+ b7 V6 s r9 D
8 T) K" X' S3 |% }
! O9 O! |! X% k* M. R8.CSS带有阴影的双边框
* N' p- b; S% ?; ~3 W [CSS代码:
+ O" }' B- z, \& {* k#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 U" w. H' o0 H$ Q& y! G
! v, I+ V# {% a+ f2 b: u$ Z7 K% [4 R7 z# x2 G3 F7 K: F; d3 f, ]+ p$ V
9.CSS多色边框' S, ]* J# y+ T6 p" G/ s; O9 j, {9 ]
CSS代码:
( |% _6 V# d7 z* u#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;
} 效果如下: ^; a4 S- L5 d# F- V0 t
|