CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
; w/ a j2 Q8 }; y3 K 以下各特效用的HTML代码相同:( m2 P7 z1 ]9 u. _
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 7 `/ j l( e) x& p* ?
1. CSS动画边框
, [$ E" h. C5 w7 z0 l2 ?! ECSS代码:- q3 x& w9 W; X. I( Q- R: r+ }% R3 l
@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;
} 效果如下:
5 P$ N7 m" R5 y5 f
6 K. U( c& w4 C. C
( o& b1 k( e/ j& S! \: E6 Q! q# ]
2. CSS图像边框
2 e1 g9 n4 ~0 t) DCSS代码:/ @/ N! M" J- U 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;
} 效果如下:
# I) D( j, T. ~0 }, n
1 R( O8 ^$ V; s( m
" j: j. [# z. Q+ ^( K( l
3.CSS蛇式边框 a7 `/ l! f Y- x- N- W
CSS代码:( C: H | L8 ]- @. u
#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;
} 效果如下:" N* k0 i5 d' U0 W; |9 f& g" B
! b" V0 U' w2 P: }$ a0 @
( a' A) N# z: g" k, O
4.CSS阶梯样式边框0 E) e# A9 p6 c" w, \
CSS代码:* C' M! n/ D+ f% 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
} 效果如下:
3 a6 E9 s0 B$ F y; f
5 t; k, U$ m) d: X2 A6 t
% z9 G2 x& Q" M" u* _& x V5.CSS只有阴影边框; W ^( c9 u7 a0 h* b+ ^
CSS代码:
* i# ^( [7 z3 @# S#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:4 p. K" | |' [9 w" t# n
: R- k: N; U( z2 K* y: w, J
1 @, y' x' u' t! B4 w. u5 h. N
6.CSS带阴影和轮廓的边框
) q% r0 ~6 M" Y) T3 b/ J7 p' GCSS代码:& y2 Y9 v" z' P+ Z% J2 N
#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;
} 效果如下:3 u6 Y: o! R( T7 t. j
- P" Y' o4 o# N& q
, K6 s I* w7 l# \8 X7.CSS少量阴影和轮廓的边框. A/ T' Q1 F) x
CSS代码:
% l' {" ]/ C8 y) ~#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;
} 效果如下: w7 }( e9 u/ q& i
" B( c* Z) _5 H p
& N- C, O5 `+ O" v; `8.CSS带有阴影的双边框7 g' L" n' A6 c, a0 h Y# r
CSS代码:
) t8 Y @5 v4 ^) a#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;
} 效果如下:' E- y$ p c1 c0 S* d: m3 y8 G" s8 ~
3 B) V" D) G0 C& Z7 j0 S
0 j* s' Q6 j& h7 \; a; k; C9.CSS多色边框& P& K- J- w- P0 ^' L9 Z
CSS代码:
$ ^6 |# n( @2 w' t0 |: U#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;
} 效果如下:
" e7 ]4 V/ Y `3 k
|