CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。0 o' s9 {9 ` \$ C: Q& Q
以下各特效用的HTML代码相同:
. {$ c7 D1 P t% l, e<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
0 A5 `2 y+ b" y5 E1. CSS动画边框/ l d1 M4 |/ Z
CSS代码:% M# _: J9 h# Y, 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;
} 效果如下:
5 ~+ x0 |6 a. K1 n3 B- _. ^
9 u6 {, B3 S9 K# ~( }9 \. p( W( @/ b7 r$ A+ l" i- i! b
2. CSS图像边框
2 m; e. y) C5 v( Y- jCSS代码:
/ c/ x0 L% m, {#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;
} 效果如下:
r$ s% Q0 W5 H: T
* R% F. U. m) i1 p
/ m7 _& [* l4 i7 X$ u3.CSS蛇式边框
5 T6 }5 [# d+ S6 qCSS代码:
' b. [! L: Q% |( m7 O. l6 z9 K/ E#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;
} 效果如下:
. l! F/ R3 Y0 a
! k7 w0 T# g, q9 t$ A) d7 x0 v; G/ Q8 o& a
4.CSS阶梯样式边框- U; Y( Q6 m h/ M
CSS代码:
+ p( \! J O4 I) q#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
} 效果如下:
; q/ t( e2 o8 f! n% f. ]
) _/ M! W0 V! K% ~6 s! O5 ]
( I2 M X1 @2 y! B" D3 I( z5.CSS只有阴影边框
. p7 w! w9 C8 V7 [" rCSS代码:
6 K1 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;
} 效果如下:
: S8 {: z$ Y3 Y& A( G
- u1 j9 [6 A/ ^/ N# L) W' x
* e8 g" q/ T, H. t, w. S5 {' ~6.CSS带阴影和轮廓的边框, K" z+ e: f* w& y" ^& ~3 d* L
CSS代码:, \& l: \1 E. K' h; 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;
} 效果如下:0 V9 c/ h7 L/ [$ I6 M
6 h* @& l2 w2 }% { V* K6 d* E
$ m$ o! u. w. h6 t$ L$ X7.CSS少量阴影和轮廓的边框
' j1 c: a' L7 u5 h8 h/ q, ?) `* DCSS代码:* e! x4 ~* R5 r: {$ @5 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;
} 效果如下:
8 E# _9 L) t0 z! E1 {9 ~. [
[8 q0 j6 K I `8 L+ _" Z4 X
" a+ Z% m" X+ G- M! v+ W9 f8.CSS带有阴影的双边框
* h4 }) J2 A$ oCSS代码:* _, {: ]* C' ?2 E/ ?( u3 l! P
#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;
} 效果如下:1 B/ R0 d9 h. J! v% Q0 x/ G+ ^* v
6 L# K) f q5 m* N% Z, h3 r% q1 f
! U! j: G) J6 z7 P! q
9.CSS多色边框2 r' i6 s! l6 o3 `3 ^6 B* E
CSS代码:' J. p9 L. g) F% k
#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;
} 效果如下:6 g" r3 r& B+ j8 M* W5 f9 k
|