CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
7 q2 {0 R% Y; ~ 以下各特效用的HTML代码相同:
5 [0 l: `7 h2 f; X<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 4 \' ^$ p- q9 X: Z& m4 Y* L+ Y
1. CSS动画边框5 Y# P! q9 p7 O& n
CSS代码:5 z# X' Z# H# w; X; } Y
@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;
} 效果如下:8 K1 l2 G9 W6 f+ r, l
g6 h# O ]8 R/ Y: z% q' A3 l& [, ?) ]9 J8 v" Y/ _" W' Q; q
2. CSS图像边框' G2 |, k0 X- [ T: H3 u/ M5 Q& K
CSS代码:
" i4 L; k W) E2 t#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;
} 效果如下:9 e; h4 m4 f3 r! N; J
$ M: M K+ P6 q1 o
0 V7 _; F( |4 {$ i& f
3.CSS蛇式边框
! J7 U3 c) K8 p g1 HCSS代码:
4 H. F- \7 u7 |5 H i3 U$ _9 X' Q5 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;
} 效果如下:1 `" i0 a, m j3 c
# G( F' x) _% ~" j- X* D
3 {# T3 x5 y0 C* B/ q4.CSS阶梯样式边框% N/ h! T4 w6 q0 t* Q3 s
CSS代码:8 D: t8 }* ~ N& h; v( s
#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
} 效果如下:; C/ k- k0 Q% N# p
& U4 C0 @% _0 J( e3 z
# I! J: u0 b0 }% E: ]
5.CSS只有阴影边框/ i- |) V. w, c* x% w
CSS代码:
; D9 D5 i5 ^) L2 k/ Z2 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;
} 效果如下:8 k+ k) f0 f* J9 \* X
2 ~4 x% u y7 H1 @" d
* a+ G) w g% T: J- h
6.CSS带阴影和轮廓的边框' B) b- r% Y: K- W9 D/ l8 }# \
CSS代码:9 R* {" v1 ?7 D# O
#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;
} 效果如下:: l( Y% Y) c% h( R) ^) j
6 E' H$ M" i! K! z' J
1 V4 l- R+ E- R8 q; O5 f7.CSS少量阴影和轮廓的边框
- N% Q7 c0 y: y6 P) ZCSS代码:
, Z" X: v" b i#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;
} 效果如下:
: }3 @: G7 R6 E: J
3 w6 P1 X6 S, V1 u% J0 i
- { w( N- D- M8.CSS带有阴影的双边框
; B% @" o$ @/ w( r, [. f/ eCSS代码:8 b. D- l. ?$ i; q
#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;
} 效果如下:
- Z5 r4 d6 r, j0 H* b' ^- K L
1 ?" | p6 @: n6 F+ f: m/ m5 c8 X% Y1 P
9.CSS多色边框6 r. Q) h0 M8 f2 M0 P5 q# i
CSS代码:' Y( o5 W0 ~1 u3 f& p
#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;
} 效果如下:
$ z$ l$ I u( I7 j6 Z4 l
|