CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。; M6 C1 X5 h) D) M: z9 M. ^: T
以下各特效用的HTML代码相同:
- k: l7 n' u C" f7 }( Y<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
2 j" E! |" N0 W1. CSS动画边框
7 H# K8 W' y( N, WCSS代码:
3 J* i) S2 N7 \( W/ G' k3 A8 s3 [@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;
} 效果如下:
& u1 l- \3 h9 F3 @: T4 |+ V
' g9 Y2 m4 g( z3 y% P
* Q% o9 a" c& I! F: p+ I2. CSS图像边框+ k9 B$ X9 z' M/ ]- C, Y4 ] c0 W: R) O% V
CSS代码:) D0 @5 P1 {$ t) d2 b( R
#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;
} 效果如下:0 G6 ~: Z ?2 I5 A- o& L; G: g( c
1 q( ^% v; n1 D. J2 q& K/ k" H0 J \/ }- @. q7 t
3.CSS蛇式边框
' r6 {1 h8 E9 O- Q; y: CCSS代码:
' Z* c$ \& ^6 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;
} 效果如下:
* J9 U8 h, r5 J& E9 s
j# L( B+ h6 q9 p3 e3 B- z8 S% j5 r$ K5 [3 w# ^/ L8 V
4.CSS阶梯样式边框, z( \; O9 f: Y" a* |
CSS代码:
4 i+ x- Y- `, \0 p#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
} 效果如下:
& {! O, S5 Q8 T" m
- R, I# [( H" U* o9 U% z T5 W6 {' d2 f# N/ M1 T5 H1 x
5.CSS只有阴影边框' A- }# P. u4 T- V4 b7 E
CSS代码:6 _( Q+ s- Y1 f4 B; Y
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:* Q" ?" ~) K6 O
; b" ^ t% s5 b( e' x/ P) I+ U/ x0 V9 F, ]9 a: c
6.CSS带阴影和轮廓的边框
3 d/ x; w* f+ yCSS代码:! v3 D- `6 }6 [
#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;
} 效果如下:2 Y+ F3 O8 z# z, M+ m
4 Y- h' r& A! m7 O n$ F+ z
' [: k4 L# U; d3 u7.CSS少量阴影和轮廓的边框) ^) h7 p$ S- C5 T
CSS代码:
! J+ K7 ~8 S- t#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;
} 效果如下: X. d) e+ A- W$ k* H
2 u& J& M# k3 i3 t! ~2 C
& r/ p- B: m% k" c
8.CSS带有阴影的双边框/ Y! r9 L8 U6 h% z
CSS代码:$ c; u* j- I9 |1 m6 N) 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;
} 效果如下:- E5 w8 r/ B3 B" t2 W. t6 @
) z* S7 x- V f# k! i( X: t2 g/ f* Y9 f
9.CSS多色边框7 h* U; w8 S+ Q9 U5 i6 g+ L1 `2 X
CSS代码:
9 a5 {: ~4 a5 f* n: {0 `#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;
} 效果如下:% e& n6 c5 ?' \, f; j, [2 ^( F0 J
|