CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。/ f0 W3 t+ @3 K% m1 h% }
以下各特效用的HTML代码相同:
# {3 s) B$ }9 r4 W<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> / H& N. _" @6 I
1. CSS动画边框3 r2 h' J, j9 H0 ]( f
CSS代码:) [7 ^) o& G) d
@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. `2 P2 E6 \( `
2 Z) l! q7 R- N3 \! P
! h$ l7 S8 G( ` f: t \
2. CSS图像边框
6 W- g$ N, H e: vCSS代码:
$ f2 h5 v h4 b/ {" w5 u0 _1 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;
} 效果如下:
~" W5 M/ D, H2 w* X
: u7 o w# ?7 V1 s; y+ W8 R
: ~7 A0 P; t$ V7 L9 p3.CSS蛇式边框
6 i7 u* l! h5 S9 ]% Z4 W- {9 eCSS代码:
; ^/ s$ Y1 t9 C; ]: j) U1 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;
} 效果如下:* @0 _9 K& t* w4 B- p& O; ^* Y
( {' n+ ~( f) \' @
3 n/ P' A) i2 ~3 x1 o4.CSS阶梯样式边框" n% |/ `0 \/ g0 D+ s3 c. j) o; \
CSS代码:
$ a0 u1 `# `* Y- _! f% d#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
} 效果如下:
# z3 |' S/ B; _) d! e6 y
# k* s% r' I, }8 _: i5 U
/ G1 N' ]. r. G% u+ c2 l& A
5.CSS只有阴影边框
: I* m0 k# U# `CSS代码:% N$ p* O! D/ B; ~$ ]3 |" ?1 l
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:; o# G: v3 J# _; E) V1 q
- v `- F5 G6 v7 Y) D4 `, I" I1 H: U& n
6.CSS带阴影和轮廓的边框
5 b+ a! N5 k- B% p" m8 E1 \CSS代码:/ n) a( ^+ E) v1 A
#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;
} 效果如下:# s/ ?/ U" T0 \2 A
; G# b, O. B* s
4 X2 a C) M f7.CSS少量阴影和轮廓的边框
4 f( Q- u: p# F7 U4 L/ g5 g! C! n5 B* YCSS代码:
- X* S$ ^/ Q& T! r* [+ }( ]9 _9 \#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;
} 效果如下:
7 i0 R! j' Y& P/ c# z; q
8 R: P6 t# W6 Z1 C1 r
1 k9 [5 u# n f& s- k8 x8.CSS带有阴影的双边框) B" }/ [& z+ p: H( X
CSS代码:
# \4 E/ M- L+ W0 `$ W* P#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;
} 效果如下:7 o" g* \- W3 f S% s
, ^* |/ {: e' w8 w; Z+ s6 \" B$ V4 Q
9.CSS多色边框& |. _# n w" E: V5 b1 w
CSS代码:- @% v/ M0 n, Y+ g
#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;
} 效果如下:/ J, @; B( o/ O3 j' S
|