CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。1 _$ I1 l' j: i' Z) R, U) W/ ^
以下各特效用的HTML代码相同:& |" L: h4 D4 d+ `
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> % j: d5 A3 \& v; r7 a
1. CSS动画边框7 X$ ^, T/ {% E$ h0 Y
CSS代码:0 v6 K; K1 L0 X4 J3 T
@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;
} 效果如下:8 U) Q, B* F# s0 H7 n9 a3 p% v
! m( x* [) f& Z; {+ U/ a; W, }
1 j. P. b- E: T2 `" x, M1 L" Q
2. CSS图像边框3 p( Y6 N1 P& ? b/ `9 K; X; g, s
CSS代码:
( r) D+ a, n1 E. I7 K#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;
} 效果如下:
( U) j+ H7 i2 U% q
) a0 S3 d& z9 u" D9 W& O6 z, R, H2 ~. u4 ~( F3 w w% H
3.CSS蛇式边框" M/ ~0 G% w- `- F2 d1 |( O
CSS代码:
: N" b ^0 F1 J @! w#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;
} 效果如下:
1 K3 g# ^$ b: a3 ]5 ^8 [0 Z
3 C3 z9 r( E7 V' e. Q* U5 ~7 g& Y2 w
4.CSS阶梯样式边框3 U' r0 U: d j5 t# Z/ d% ~! `% @
CSS代码:. h, v: b6 T" H) C4 \7 H+ T
#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
} 效果如下:
. E3 I9 t" J7 _1 x; \0 s8 P; V0 @
H5 R" h0 C- V9 w$ ^9 @! h+ Y6 E. }$ z% J4 e/ c
5.CSS只有阴影边框
T9 E o( H4 K8 {: JCSS代码:3 \5 p0 K7 i8 S' }) O
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
- ] S9 W7 G7 a( H( s
# \. h, M7 Y) M; h' i
- V# A8 J8 }/ D, s8 j/ i; o; C* q& P6.CSS带阴影和轮廓的边框
. m+ p- N, G- k: _4 L/ D, bCSS代码:
. [$ x2 U6 X+ b; X$ R4 k, `#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;
} 效果如下:+ |' `3 q2 A9 W3 a0 E, N9 _; ]
1 x }, j+ Y( ~( l: n5 x2 t+ _$ K
- w$ |1 W& U' w2 O5 w7.CSS少量阴影和轮廓的边框
4 y+ ?) v T4 E2 u8 ?CSS代码:( l" t' C0 A' L: m' ?6 t: l
#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;
} 效果如下:
+ U% Q0 C" ?# F! w
! h* c, v* u) |5 j, o
% t; d& R& B3 n0 F% D7 [8 l' H6 X8.CSS带有阴影的双边框$ i4 b7 m+ @/ a* k ?
CSS代码:4 V) b' k; w+ j: |; i( Y' w
#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;
} 效果如下:- I- a# W6 }" [) v3 |1 E
% ?* B5 J) ~2 u4 u) x
9 E' N' \8 @: V4 P# {& B9.CSS多色边框
- A' d3 U, e( J* t& SCSS代码:3 |5 D% Y& E) J6 f ~) S. v+ c; h
#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;
} 效果如下:' q) _! A e0 O) i7 W
|