CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。: w7 `. r6 `' m5 }# V
以下各特效用的HTML代码相同:
! X0 z- P+ ]+ W0 o1 E<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
/ E/ }. ?- j' R& E b, c1. CSS动画边框
O1 }- ^( R H' cCSS代码:
5 j, b3 i2 A: p, v7 E4 S* b+ V@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;
} 效果如下:6 m( G: K! w6 }8 l3 N5 l
K+ ]4 K1 o9 _3 y
$ ?6 ~8 f1 w9 @1 V
2. CSS图像边框
' U4 s$ a9 A2 V% P; l- ?CSS代码:
5 t7 `6 O" x! y# ]1 H+ }/ ~#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;
} 效果如下:
0 x: k' O2 [/ L9 d C1 ]# _( j7 z( m0 g
T( A. g, t" p6 G
+ w9 y: ?5 O6 k! b( b2 j8 p( q3.CSS蛇式边框- M5 E, k( b& l1 O4 |9 X
CSS代码:
* W! Z" o/ b: C#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;
} 效果如下:
! r% S" M7 P6 D) B; O9 j
$ m+ d! k! Q8 q
& m7 t1 b. [$ @) g0 A/ F9 f/ y4.CSS阶梯样式边框
" W* |' Y+ l/ P) a) ICSS代码: E6 U, k* W, N8 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
} 效果如下:
# @! m7 @$ G% A/ H* V# L* O4 A
3 z3 N8 f, V" Z7 ^' l- ?9 O
8 z- y2 Y- h' v. @% D5.CSS只有阴影边框8 ?. u, {/ y* z; x1 U1 b- h
CSS代码:
* y: Z' Q* X' s( n' _6 `#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:+ u) Q( t& y _1 f( U* T1 ?
+ F8 U; r0 e7 S% @4 _; H
* k' U4 z/ D, v) _& M6 _- y, b6.CSS带阴影和轮廓的边框7 B* Y) Z1 E3 X' _5 R) `" v
CSS代码:$ q X4 \8 I0 I- k
#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;
} 效果如下:
6 F0 H D G6 H4 }
, C$ K# [. p; z
4 I7 s* j7 L @) J; {! Q4 p* m
7.CSS少量阴影和轮廓的边框4 F4 V4 q1 U* [
CSS代码:
9 r" C6 e+ C; 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;
} 效果如下:
+ Y& g9 j+ m5 z# ^- n
# ]0 e0 \+ ` I/ Z5 J* c0 @6 I* l4 e4 h" A" p K9 N
8.CSS带有阴影的双边框$ b: Y2 L% U, O! h
CSS代码:
. L( M; z* A% j8 [* z! [9 r* ]/ i#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;
} 效果如下:% R, A7 x" }4 J( V/ M* v: R
7 U4 V' `$ Q. `
1 _- o. E8 T" S( V2 p9.CSS多色边框
0 f1 r M/ r0 l9 @/ z+ ^CSS代码:
+ U4 O9 b0 I* t \#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;
} 效果如下:
, c# A9 L: N2 a$ _/ C! E
|