CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。' s. ^: I2 F/ }0 F8 J5 q
以下各特效用的HTML代码相同:
4 i; o2 j9 X0 M, a; I<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> : V- g* y9 k2 K/ @
1. CSS动画边框/ ~2 {$ i( ]7 {* N& o; {
CSS代码:
' G, U& X9 b, B5 V! o@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;
} 效果如下:3 K% i+ H: h7 k
) A r& C; @* Y& A3 A: ~* p3 {$ u
+ p! b$ h& n9 G2. CSS图像边框3 h- Y' ]. i( r) m3 C3 Z
CSS代码:( X e6 E! U+ X+ u
#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;
} 效果如下:' X f/ |% |- O3 }" y: q
7 A5 K. H% g# [- P8 i; x+ L a& X7 b2 n
3.CSS蛇式边框
8 _6 w8 k- V" v1 Z4 j+ w, eCSS代码:0 u! [/ Y, T) e& y/ I2 O: h
#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;
} 效果如下:4 U2 Q* F( q5 e% J& A
2 E5 M% C F+ Z5 @9 k
/ u! N6 \! `; e5 }) C
4.CSS阶梯样式边框
# L* b+ D! M' N9 X- b! n; SCSS代码:; S! u1 [4 B C3 d- c1 y9 M& 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
} 效果如下:. p3 g) \ n) }! X0 r
, [: J8 P1 S1 M
0 F. Q0 I9 c+ w5 r2 C$ r) Z
5.CSS只有阴影边框& c8 I, `/ l3 G, r5 F; o4 O# }( |
CSS代码:! ` w4 Q0 X. I* k) E$ k' ?
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
8 [" m$ e; }. ?, D0 O# J
3 n2 I# d3 g6 A8 P2 ?; E
t! C5 J* x+ E, a1 h: r6.CSS带阴影和轮廓的边框
& Z( Y1 x, j; _$ H& h1 g3 p1 q) cCSS代码:/ W( H: ?2 [* y! G9 o- w _7 D6 {
#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;
} 效果如下:3 n1 Z2 }: u/ v8 F8 L, g
% M$ x" F) z4 v, z c: w# ^* ^, Q( X
d1 {- j' I+ l" \ Z7.CSS少量阴影和轮廓的边框7 S3 s4 n; Z0 U5 m% {5 b* h9 J
CSS代码:
?9 w5 @) n# r v2 l#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 ?' S% D; x% }% a; N
8 c: l- Q: o5 I% H
) H! r% X9 ?1 y6 y
8.CSS带有阴影的双边框
, j. n, ~* |. p2 [( ACSS代码:" x. i* d7 ^4 ^
#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;
} 效果如下:! Q$ s5 k6 J# J2 c) ~" t# K6 n
& t9 O/ x) H) _8 U1 F
9 T, _- A, U& q2 |9 w+ i/ h% x9.CSS多色边框 H6 a8 E% }- c5 x
CSS代码:8 e: d# I$ b W$ {; z$ i/ Q" M1 r
#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;
} 效果如下:, [7 J; X1 G+ ?7 b1 t7 N
|