CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。# @1 T- P9 I# c3 c/ r M
以下各特效用的HTML代码相同:& v4 E. U1 `# S! x
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
( d `4 y7 G' b7 i1. CSS动画边框: y% A1 J; k9 f T6 {
CSS代码:; P- ?7 C0 f5 h. P
@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 I3 I; r& z K* b% Z) P. a
3 H$ }- f8 O, c9 |. G+ h0 ?! l7 _% @8 i
2. CSS图像边框
! e& |6 U+ ~5 K5 S0 WCSS代码:1 m! @) s! \" \8 J' N! z, P# w
#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 B$ V7 B6 F0 K4 T2 _9 g! g$ e
7 ^$ T y( j/ [& {
; x6 }* r7 w3 f9 L6 r# v1 s3.CSS蛇式边框
* J* V& d. v* F* {CSS代码:0 T5 u. h5 h) x# G" f
#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;
} 效果如下:
3 j8 h* ?& d) u$ D% K2 n
6 O% v3 ?/ l# [# j- w
! p" X6 a! U" c3 l& a: ]
4.CSS阶梯样式边框
/ \ a$ G5 K! P/ ]$ `CSS代码:4 E: v! L: M" z$ [2 Y3 X3 `
#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
} 效果如下:
) F: r3 ?7 G. s+ \+ c* i. C
, _; ^' e3 E; U9 Q! F- H# e! Y- V
0 o0 j% Q0 U! j5.CSS只有阴影边框
) R( c; J+ u% y: U! n% oCSS代码:
/ [* u- m! M4 d( }5 M7 d#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
/ B, a# a* E* e: u8 ]2 {8 k [& E
' b) y# r) A6 v2 n( }% t
: M+ M+ L" y' j5 C. |8 d
6.CSS带阴影和轮廓的边框
( v8 Y1 J, e2 L7 h* _% `2 Z. `, ^CSS代码:1 m+ l3 ]. `8 y8 b. Z; ~
#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;
} 效果如下:
& i g# m) k0 N5 K' ?5 W
4 K, N+ s9 W! C2 h
) R, W1 Y2 d+ Q* C7.CSS少量阴影和轮廓的边框# u; {) n5 V/ a9 I$ B
CSS代码:
0 k v3 n1 K' ~. s7 \#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;
} 效果如下:( A' E( F2 H* s Y
( l7 F# d, N3 w8 v, R
8 u2 s4 X k0 C& f! n% B" f1 l: a
8.CSS带有阴影的双边框3 e; i1 P7 c3 N+ }, S- ` b9 J+ ~* J
CSS代码:' V4 Q; B" x+ Q5 e4 N* J8 ?( S! L( 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;
} 效果如下:
: y- X; r, e) `) N4 R3 W" j
' s5 K8 l# `/ F0 k0 A; k
# z0 T. }" w5 j/ O% Z9.CSS多色边框0 t! t! n+ m; w' ]
CSS代码:
w9 j9 }! m9 m( [#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;
} 效果如下:
8 y! M( R* I% L: h* i0 E) q* a
|