CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。1 V% ]. ^7 t: Y( u, I8 o# X& G, b
以下各特效用的HTML代码相同:
2 x0 `1 g" Y3 q/ r$ m<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> / f2 b, Q/ s0 ] k% C
1. CSS动画边框
! d5 ]6 `9 }& g) a7 s6 R/ XCSS代码:
S; a: O/ a0 l" b, {; Q7 d6 N@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;
} 效果如下:
+ |' d* h' c8 O/ z! c
; C" E9 N- R/ ]/ N
0 Z5 s* j) q5 R: h/ O5 S: E2. CSS图像边框
4 d5 h% n* l0 b' b3 ~# dCSS代码:; t! H( I9 G" Q! _2 ?" n; V, @0 P
#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;
} 效果如下:0 x$ \' {3 q V& H" v1 b
( X, s+ x- P4 r
( ^( m6 U% P0 G2 `! B3.CSS蛇式边框
* ^. z% R% s( P* _' }+ G& }CSS代码:0 C1 a* Z2 s* E" [( f/ L
#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;
} 效果如下:
. t' H6 k1 g9 F4 J% r; a6 ~/ y
( K+ z- l* _+ e% N3 A# O1 T
1 z8 Z1 g4 ?/ g+ y! U9 Y' Q5 `4.CSS阶梯样式边框% z0 ?: u" \: d" Z- j
CSS代码:6 M9 z) Q D1 J6 X) O. T) k
#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
} 效果如下:
* g7 Q" V8 [& d' C2 r. {& q
4 @6 R0 J5 ], I4 D, O0 Z9 U3 H( ?* E+ q0 A. A7 M
5.CSS只有阴影边框/ M; H) x0 S' H2 i
CSS代码:
4 B$ A0 v7 |$ i#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
6 k- _/ b9 k$ |& i
8 f8 L. m0 b1 i, o
6 K$ a) q0 u- v, |6.CSS带阴影和轮廓的边框
2 l/ Z& ~ h: B8 x9 h* M" jCSS代码:9 [8 ~3 s1 j- s# 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;
} 效果如下:, w1 Y u a u) v5 g2 j4 f- S
# x/ y6 r* F, ~, l+ C1 ?6 g' }
+ R. J+ A/ X( |9 Z d7.CSS少量阴影和轮廓的边框" e9 }* j; j) Q3 R0 I% H: v
CSS代码:
. x9 m0 W A8 q4 i3 Y3 `#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;
} 效果如下:- a5 ]: I: q. Q m. T
. t% c1 A e% ^, B( T. e1 O" e
$ K1 q: f3 z9 N( ?5 d0 m8.CSS带有阴影的双边框4 Y( K0 V! L1 A1 k- S
CSS代码:
' y( I# z1 r' O' ?) B#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;
} 效果如下:
& o5 ~5 Y7 n; V5 t+ S
% }; G7 y- ?* S' I% w, ?2 L
. _' ~. j% v9 d6 D9.CSS多色边框0 V; @, s8 A# S1 |
CSS代码:6 f/ w7 T/ Q* e4 B, `3 R( [, y
#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;
} 效果如下:
2 K' X+ B) k0 W3 L4 I- |
|