CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
" o3 j W( f# P- ]7 b2 c( J 以下各特效用的HTML代码相同:6 N! d* b3 F' G0 R/ C5 B
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
% ]8 w, t/ ^0 P0 }1. CSS动画边框/ Q( m0 z: N/ j3 @" }: _
CSS代码:
7 ^/ _* n" E- O& ]0 _$ f/ p0 b@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;
} 效果如下:
! L$ v$ ?& Z# ]5 `2 f& n
6 h& l9 s3 f# h* g y( @1 G
" o6 J" L. y5 L4 E( v8 W
2. CSS图像边框, c3 M/ B' P* G8 L1 t
CSS代码:: B) b2 R5 I0 Q* e. E
#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;
} 效果如下:/ H J: w4 K6 `1 k `5 I; N
4 c# c5 B: g. C2 n
9 \2 S! o( ^# N/ C: w, A
3.CSS蛇式边框
2 f7 ?: E9 q [& k$ ]CSS代码:1 j. Q# ~9 A2 R2 f& l% N/ X, H x
#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;
} 效果如下:' R+ `( y6 }! c. L6 e `/ J
2 B$ e% j d0 A$ X6 ^( B9 c9 q4 y$ \7 P6 ^2 B, B1 r" X
4.CSS阶梯样式边框, U2 X7 B9 n$ Z' J9 M
CSS代码: T/ R% h/ m1 y# X4 f/ x2 m/ n# J
#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
} 效果如下:: m s( j8 d! ]( i |( b5 _; |
' j) B) i1 \5 y6 s. B$ Y" E
' y' \+ n) \, l5.CSS只有阴影边框7 |9 M. ^0 \" Q0 g
CSS代码:
" }% B" ]3 f8 ]' m4 G( y, 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;
} 效果如下:
. m& t/ T- v! Q9 z& P
: _* N5 q7 p }( j
5 |: V2 P) N* u& `/ f% i9 G6.CSS带阴影和轮廓的边框
4 X; K& M$ _. T$ G! T+ G) t, NCSS代码:& X1 I x; I! V0 V. t6 C
#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;
} 效果如下:
7 G, I' r' y! T: O& p
; [+ H1 {/ i% ~* d/ r1 \: [0 a/ i9 c# ^, n4 {6 V7 N& d1 ]3 Y% ~
7.CSS少量阴影和轮廓的边框5 p3 a8 b; ]) R! s
CSS代码:
2 V0 ^3 _( `- \2 H1 X6 g. z#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 c# n. O% U$ R9 X S! ^
8 z/ z/ |& B h. M
% U7 H4 O4 k* H# h- f$ B. _8.CSS带有阴影的双边框
, G& A5 H% j+ K9 K& Y5 {CSS代码:! M4 k& Z6 q4 ^
#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;
} 效果如下:
4 N5 O1 L6 _; x Z4 f
0 J' m3 {- f# G+ u: p7 C" j
3 L! c2 A5 a7 ~9.CSS多色边框
# ]) H9 b6 p" B2 s4 k% q$ b. u8 p: mCSS代码:: O& j6 K: g; A$ c0 {1 }% `
#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 R# X% {# n
|