CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。, \; |; J T) n: s% d5 |
以下各特效用的HTML代码相同:$ M+ F9 e# e; Y
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 8 A4 P6 X+ `$ N+ ~# V/ C; U
1. CSS动画边框. a; _3 Z/ V# m0 M/ C2 c" r
CSS代码:; V* V/ }$ P! Q, J2 }$ y% u
@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;
} 效果如下:3 O; z) Y: c, b& x1 }) C% I) E
9 K( _; s1 v, _" ]* V6 D, |
* \2 P* P/ Z' C$ X0 H4 s5 ~+ y S
2. CSS图像边框
; f& P8 B3 ?$ M) g' XCSS代码:& ~3 _6 M L2 x; N7 a
#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;
} 效果如下:4 {3 k2 V8 n( `0 w5 _. Y
: Z: O8 C/ A- b! Q f: J4 ^
7 x3 s( J, ^ I4 b- J
3.CSS蛇式边框; ~. u, A7 U( p; ]1 u
CSS代码:
) u' T" |6 K* Q$ U( Y/ }- ?6 ^4 a {#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 p1 `/ [! b5 o: z2 h9 i* U3 S- m
$ |7 ^% J+ H# D ^& y, a! P
/ h* y9 l2 h: C2 S. F/ d, b4.CSS阶梯样式边框8 [! W) I! j. _6 A7 {) X) }- w
CSS代码:
: z- p( f8 W4 L2 G! b#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
} 效果如下:; T! K0 e* e6 k) X4 ?6 X6 y
3 x6 ?- w+ x! Y9 ]2 ~! p9 L! r
9 v$ L# v; t% k; L4 i$ k5.CSS只有阴影边框
5 `9 b& ?0 D8 I5 ?" `0 r2 y' [CSS代码:
% z6 k+ R" w8 G4 a- Q#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:' G* s& z8 V/ A2 ?. G& z: n
# t, C$ J4 m5 s6 |5 }$ ?2 I6 C; o; [& T7 N% r
6.CSS带阴影和轮廓的边框
* ?% e) G+ ] l+ [1 k' S5 BCSS代码:
$ D4 i K% j p$ P0 |+ ]0 X#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;
} 效果如下:$ S2 I- F" R5 Y3 \, \, n
1 E- K& n: r) \9 o+ q, _4 ~) c; A& R" x
7.CSS少量阴影和轮廓的边框( U) |( M/ a% U' V
CSS代码:8 g6 ^9 u8 r" X: n1 o
#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;
} 效果如下:
0 v. L6 s1 o* G: m$ o9 N
/ F8 b. F: d( F' m: t
. \ v& b4 u% U# z9 {8.CSS带有阴影的双边框
$ a5 K' y6 O+ j$ YCSS代码:: w/ A# ?0 {7 a& [# j
#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;
} 效果如下:
" ]% _ d9 s1 M- |
# B& a: I' t3 Q! D8 `3 D0 I
- d: a4 w9 U) t- e9.CSS多色边框
3 x* i% m, W/ I' }CSS代码:
) i3 W, n. D' V, {5 h! l#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;
} 效果如下:1 u8 C7 n7 H& a8 \
|