CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。6 n& K+ ]& }7 G; E2 x3 _, \
以下各特效用的HTML代码相同: a. _7 U8 ~# ^5 R% t3 A: Z
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 9 o6 r3 A$ R' |
1. CSS动画边框( ^3 q5 }, z: X
CSS代码:! B" Q4 v0 C& ~; o4 ^6 Z0 |
@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;
} 效果如下:
. K0 t9 ~3 j6 {, \* e( @
, |# j" y( h) @7 M" G# A
+ z8 C; L/ u9 b ]7 w& l: _/ M2. CSS图像边框! m8 v! F2 ?. ]( V: {3 g1 v
CSS代码: L9 a7 o7 l6 q( w, u& O( I
#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 I" C! \6 P: d& K
5 K* ^. ?7 b7 f; d
# G6 @! _0 a9 o0 y# }3.CSS蛇式边框" m. U1 ^ q; _6 A9 Q5 P: v
CSS代码:3 b3 M- a$ \* q* y8 N& C& N
#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;
} 效果如下:6 b+ S, [ U' ^7 O! h0 V
* C# w& Y7 u( p/ n+ D* c7 s
% ]9 [. m3 H# P! o9 V2 K7 [
4.CSS阶梯样式边框
* v& C+ l% x& F; F( ~5 k% O LCSS代码:
9 U& t5 w( [1 U- {#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
} 效果如下:
- i+ ~7 d& {! Q2 p
! E8 D; z; Y: `: x. C4 J4 |. n
: `8 u; l, z' y' X: O: {5.CSS只有阴影边框' X4 [, a# Y x1 O0 o
CSS代码:. h' S- D; G& ]% W# p# u/ n! e
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:! F1 } N' Y e/ f8 |( H8 Z8 P) ]& g
4 P8 c9 E+ w$ ~' }9 f
- `4 y- g2 y- s6.CSS带阴影和轮廓的边框, C! h! y. _ n: F S) q
CSS代码:0 C7 v; K, g, ]0 M0 S1 m4 c# H- ^
#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;
} 效果如下:4 B1 d% } V1 Y! y: A# H- S4 i
' Z! x1 j3 B# K# A
8 g) M0 T8 n0 ]* z7.CSS少量阴影和轮廓的边框4 `; c2 B) O- I$ z! E) |, ?9 q$ [
CSS代码:6 \# {, Y) B9 p
#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;
} 效果如下:
+ ^: G/ {+ b8 z% D( X$ J
# r9 _( w9 Y% e1 g" W( f F% `$ D a7 E: a' y2 {+ [
8.CSS带有阴影的双边框; m$ d( Y2 @: e
CSS代码:
' A) u6 K" s# ?: s4 f$ o# G9 ?#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;
} 效果如下:4 m8 F4 m9 ?9 |' R7 y
7 r ?! P9 r0 k# }1 W% P
, V+ R4 m: \% t3 P% b3 a. C9.CSS多色边框
: O# j6 S) t5 K4 Z8 W0 s8 F) zCSS代码:
) F0 v5 G' r4 I& D; s#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 J/ Y# q! K4 c, d
|