CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。; X. g" i: k% X4 ?- C
以下各特效用的HTML代码相同:( M8 r0 i+ _- k! }* J' E" q5 J8 i
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 3 M, p! Z" K. v6 x- B# |) T
1. CSS动画边框 R, A' C1 L q9 C# R, q
CSS代码:0 i: d( n7 x- z" Q, L/ C7 s
@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;
} 效果如下:+ V8 F u$ Q; n3 v$ n1 K& y8 @& J
- ]% M+ P; v5 I$ c' O$ u
3 V: E8 J$ ~0 p9 X" y2. CSS图像边框
1 g/ M: E7 s* eCSS代码:
- f. B1 ]% p/ h3 b#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;
} 效果如下:
- Y3 o0 c2 ?* n4 R5 o5 P! g6 o$ o
S2 ?1 C% ? c/ R( ]: K* ~5 `" }( {0 V/ E$ Z1 L" s
3.CSS蛇式边框) M( ^! `) {; ^0 R V
CSS代码:
7 J+ A4 _0 @" S4 r( _8 b* b1 P+ o#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;
} 效果如下:
7 q/ N2 R3 P' ~( n5 \$ D. O
8 g ]4 o* [6 G7 i6 U! v7 ]% X, u/ O
% D0 l9 I/ {. ~' a& I4.CSS阶梯样式边框% ]! `3 l( N3 R4 P
CSS代码:7 I3 I$ l0 j" o
#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
} 效果如下:( q6 v) o- S6 _) `
2 s& R4 l% N6 J- K8 R7 i
i5 ^8 V: a* i& O5.CSS只有阴影边框2 o# P/ S6 V; r# B5 J7 J) [ T. w
CSS代码: ]! A2 g% w& }5 b; d, T
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
) {, X2 n2 _* t8 a( Y, _
0 A6 b2 o9 g$ W# A0 J1 B2 P
: r" U# H5 i( l/ O; k! |
6.CSS带阴影和轮廓的边框, ^. B5 e- p3 A: }. h" E# b
CSS代码:) [8 F( p2 @) O7 m5 `
#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;
} 效果如下:4 T' u1 _$ t6 r$ y" \' {
1 i9 R: H0 G% c) k) Z# G$ i1 S0 w
$ m; C4 |/ }0 {) J2 p' s! P7.CSS少量阴影和轮廓的边框
# b/ s+ n* J$ O$ P# M# \9 j; N, S+ QCSS代码:
8 f% ?/ ], h4 Y#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;
} 效果如下:
# g- m: X" y& C' B/ C0 w( _( r, n
" p. G l$ i; o$ v
/ V) F' ]+ {" O8 r( H( h8.CSS带有阴影的双边框
, g4 E4 }7 R1 _' N- gCSS代码:
# A% V' P$ L: c1 L, l#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;
} 效果如下:
- t4 b4 X4 t$ a* `
' @1 Y5 p8 p# r' f9 e
7 q+ ^% _0 D1 i# ~8 A" y9.CSS多色边框3 \" b/ l C* U
CSS代码:
9 X) `7 o7 }0 d4 u; C#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;
} 效果如下:
+ [# g2 I3 q; k& H, M0 D
|