CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
, x$ `! F9 j: P, \3 y" U3 D; i 以下各特效用的HTML代码相同:( F, f- P: ~% Y( K3 n. p
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 8 y1 h& y' ], ]& I# p
1. CSS动画边框
$ `' M8 J' T, a* Y: j/ G, HCSS代码:
/ U& f" z9 h8 }' O) n0 i9 H# Q6 J@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 Z/ Q& w8 L/ W
% u: P4 W% r$ a1 a6 L2 x' H; m5 {" m: b4 j$ Z
2. CSS图像边框
) Q0 Q6 @; ^' [6 @% MCSS代码:% z; } R# X' q% o6 k1 g D+ }4 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;
} 效果如下:
1 X% @7 G5 R% j- S; C
9 V: f3 O0 e# T$ c+ ?" g) ?; @2 h8 l2 i
3.CSS蛇式边框6 A9 P, C1 M6 }7 r: o
CSS代码:6 X5 P: g) N4 \$ t( H+ I7 X& V
#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;
} 效果如下:) S/ @7 o: \& Q0 O# j. i
% u; P+ j& m: G, l1 w# M: j% q5 J5 i) i
4.CSS阶梯样式边框& A% y! v' w. F
CSS代码:
Z7 F% ]& Q2 q. C% N6 k% D0 @) L#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
} 效果如下:
% h' F. G k7 A* n- y5 M
( ^) h& z; O# I' _& u% k5 d. {7 d
8 b+ J& S9 n4 z- W5.CSS只有阴影边框7 c/ X o6 w$ {# j. E
CSS代码:
. V2 g5 y- p" p8 w- h0 Q6 s#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:$ P0 C8 G5 ]/ b$ o/ c6 b4 j
8 t+ j' q1 o- J' O8 D
3 y1 g- a0 k' g: s
6.CSS带阴影和轮廓的边框* v0 F. G, @ a5 Q
CSS代码:
, S7 s( I; H) A1 B( M$ K6 \#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;
} 效果如下:
! t9 y4 \: _. p8 d! P
2 A9 I5 G8 p7 }8 |
' ~7 D5 [/ S1 e& ^
7.CSS少量阴影和轮廓的边框0 L: v9 h/ O) d7 ]1 x" v) w
CSS代码:
* u; \+ Y. @( H- Q#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;
} 效果如下:
% R1 r8 Z" t2 K8 @' F( Y4 @, k
2 ?$ x O3 Z, i) M
; |5 s+ J; ]5 M+ O J K7 i; v8.CSS带有阴影的双边框
9 N% H9 L# n1 mCSS代码:
* \4 F8 C6 y$ x& l2 n, 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;
} 效果如下:/ X. P1 w! }. {3 s
8 c a( o* b W9 A$ ^
9 o8 ~* |8 ?6 N8 p$ @3 r5 o9.CSS多色边框
/ B, ]& K. t( ^2 J9 i* XCSS代码:
9 b0 D/ P1 L; ^ b* r- n#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;
} 效果如下:
0 g. s1 \8 O6 ^/ ?9 L6 C ]" |* ~
|