CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。' h! [% F1 T- z$ K: Q1 y% T
以下各特效用的HTML代码相同:
8 B: f8 F" H' l. W8 ^<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> ! H2 E: Z2 _" L9 e: H" W8 ?
1. CSS动画边框
1 f0 Y3 z% I4 `! tCSS代码:% ], u+ v( S/ e S1 r# I" h2 D, d
@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;
} 效果如下:
2 L! v$ L4 s$ L5 m8 }, _
1 H/ [$ E4 V1 W4 q" I4 b/ x& X* P
9 Z$ n$ O% o K5 T0 n% E( F, Z2. CSS图像边框- |) s/ ]+ U# Z, E. ~
CSS代码:
4 X( h' H. ~; H6 J" [6 H3 ~7 {' L3 k#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;
} 效果如下:
# A0 P) Z: ?0 C) F7 t3 u# d
7 b4 [" M/ Y A3 t% z9 Z c$ e
: `3 |5 J) b& q5 |4 m( \3.CSS蛇式边框
! }5 T1 q8 s ~4 s4 RCSS代码:4 E: f% s/ 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;
} 效果如下:
$ i2 W5 U# S. ^" ^! R- J% o; q( ?
) B1 f6 l7 W" C9 u
) \, u( A: a( g4.CSS阶梯样式边框, U8 ]; H4 g1 d, f# ?. l7 t
CSS代码:2 {" z- i0 z/ |6 E9 ?; p! D
#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
} 效果如下:
' P" h* K) u6 r; X, i
, U, H& }6 s* [- I1 n$ v8 L) X: [* u
5.CSS只有阴影边框
" R4 F7 F3 L1 T0 [* XCSS代码: j; r4 t" Z. Q4 ^* J5 r
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:% M) e4 x9 ^$ b
$ f5 U/ x: d w& f# E
& U1 V9 }$ S0 c, X0 T+ s
6.CSS带阴影和轮廓的边框8 C& Q9 |* I- L% g& A
CSS代码:( v8 l) F, g' _7 G5 g6 h2 \
#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;
} 效果如下:
5 G# m( p) n1 v+ u2 s; w
1 h/ n- d- H$ {7 V0 p ?/ b) M' f; F# O! J; V: K
7.CSS少量阴影和轮廓的边框
' \& Q% Q5 \0 jCSS代码:. C# O: e* \9 b# G/ h: W- O
#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;
} 效果如下: z3 D2 D- T" W; m: |' S3 G
" |: t; e; C1 v
( Z5 Y8 |! j4 c9 w4 ^
8.CSS带有阴影的双边框
, x5 G+ _+ W! c; M0 V+ @/ u3 BCSS代码:0 ~# G) S1 I; k4 }
#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;
} 效果如下:
/ z) n+ h& O2 ~' M
# h1 A! \$ G4 G. X# o& N/ n E! j2 L( E
9.CSS多色边框8 y( K% J/ b$ g+ j; S
CSS代码:
- K/ h2 u$ l. C#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;
} 效果如下:
+ _) l# p% J2 {5 J% s
|