CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
3 Y9 {4 o! [! n8 @! K8 G( \ 以下各特效用的HTML代码相同:1 d$ g. f6 E6 ~- s y4 K
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
9 u: Z3 s) X+ D, J% `3 ?1. CSS动画边框" E5 d0 e- u, o3 p3 M% r
CSS代码:
, q& b9 }8 {7 q# p3 _@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;
} 效果如下:+ f! {0 n0 y1 s$ N5 o
- f# E0 k7 v, t" o$ R* J
! o! d$ A7 f5 a; B/ ^3 r* L
2. CSS图像边框
6 M, q- r" Y/ b: i: `6 r9 \$ jCSS代码:% J! K: h8 G$ B: @% t- c$ Q. f; `, _
#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;
} 效果如下:
6 e; a! N8 B; m7 _, A7 ?* G
( u; q: z Y* Y, u- X2 r# }! V
$ r* U& ?0 L% H6 s" L0 a- r6 i3.CSS蛇式边框
% l. K ^# Z* f% K! e9 f7 T1 @6 RCSS代码:
9 s: F2 ]/ ~$ o+ G- x) t2 X#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;
} 效果如下:7 j& W% t& [0 r3 o7 p2 ?& q- U
- s0 [- l" b# y0 f
: u9 U9 s9 ? U3 X4 U; I8 P5 O: q U
4.CSS阶梯样式边框+ v+ J6 L0 u4 B( d1 b; Y' x* i
CSS代码:
; [% M, E# q3 g) Y6 |#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
} 效果如下:; l! d7 A- ~0 p+ }/ U% t( p. Y, K
' o: x& H" }9 Z; }' u* f3 k7 V% S
: j# W& T H4 [5.CSS只有阴影边框/ G; ]! w; O1 o3 z5 K4 @
CSS代码:, S3 j. {8 Y) {+ G% f, h
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下: k; M8 Y7 L3 [) U' q, w% Y3 ?3 ]- s
/ g0 L) \% ?2 Y3 Z1 q4 Q# m; z% |
. k2 j4 m6 f: e6.CSS带阴影和轮廓的边框* i5 c& h# Z, [: j t, p8 M
CSS代码:
! R1 ]* `% C6 M& d#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;
} 效果如下: O; p4 }# j% ]' T' r
1 S/ h+ d1 v6 A' }; ^
* w6 S9 v$ s/ L( H7.CSS少量阴影和轮廓的边框
! O. U# W: T E- }, N2 W8 p5 N7 GCSS代码:
; L4 }1 b+ B) t' O+ ^- j#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. l+ U8 `9 U. \. ]- D4 K
8 [: {$ V7 }% U T5 [5 x+ \
" ]5 u3 L( P, ^' N8.CSS带有阴影的双边框# O8 O4 R. [0 b
CSS代码:
- f) B& h) O2 @! J#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;
} 效果如下:3 U& j) v+ ?, T) X, \( L P
( h, a3 c! k7 [# r" U
m7 H4 }* ^( Q$ p4 ?: M1 }) d) v" s9.CSS多色边框6 _, ~% i7 M# [- v0 U% e, H# \
CSS代码:
( `: X/ P1 }: Y8 Z; a$ w1 E#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;
} 效果如下:
y+ y2 @5 b6 L
|