CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。+ C( d+ T6 P" c) ^) r
以下各特效用的HTML代码相同:# x+ r$ _( b( {4 o# s& z/ D
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> # x1 w+ G" ^0 Y8 y! ~8 W. j
1. CSS动画边框
' F3 Q {$ h5 {4 e- _1 [! _$ sCSS代码:2 w% i) b6 }' f& M9 J1 c
@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;
} 效果如下:
1 }, {7 w. g5 ~$ A# ^ [
; q$ B; c9 o1 @
+ O3 a- B J& d. i- x
2. CSS图像边框
3 j3 c" @4 ~, o, ?8 [5 c5 ECSS代码:
2 j0 h4 j! _4 u% ~- ^#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;
} 效果如下:, v" b' t B# y4 S
1 @! o! z' N3 H7 b- l' c5 U1 f5 S3 K( X8 X$ ]# l" c0 ]. ^9 U
3.CSS蛇式边框
: N: H! t" v+ f) [& Z: |" }CSS代码:! ~# I6 ~1 Z& `; L
#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;
} 效果如下:( `& y o/ u* d
- s+ I' r+ E4 k6 e4 K; Q6 V& W
: ~- h3 N/ J* [# N% _1 b& Y4.CSS阶梯样式边框! `+ l: V; O. l# a" r, M" ~
CSS代码:
, p$ ^- V3 H6 u# t3 a- ~4 V8 p& M2 d/ K#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
} 效果如下:; N {2 A- U Z# [1 k
- E5 P# I* K2 q+ l- e
/ \ O/ [& L" m% O# z5.CSS只有阴影边框% F+ ?) ^* u) D
CSS代码:
. T2 u& j$ }- W2 U+ `* K( M+ Q#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
* p6 H* s- u. w* n
5 ^. E) a2 A6 j- |- P/ Q& `: R ^: J/ C* [6 }% t
6.CSS带阴影和轮廓的边框
1 o4 W* w2 V1 p; ~CSS代码:
3 }# d; m2 f# p3 Y#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;
} 效果如下:
. k* O4 H; B! o
$ y* t3 g9 l# j( A
# B8 v3 q; v6 m, z$ T; ?
7.CSS少量阴影和轮廓的边框9 Z3 S* U- \6 g7 j3 d
CSS代码:
5 W) d% Z$ m5 x, E4 J#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( g# f6 ~+ r7 f! g
, G8 c3 c6 h" F% @% }/ V5 X/ \6 _0 S& n# c- _
8.CSS带有阴影的双边框% f. K& z4 L/ P# R" ^
CSS代码:$ _9 s# Q4 Z& t8 j
#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;
} 效果如下: g+ g( r/ e- Q Q: K
( x, ^( |6 C: c* x' b& z1 i/ I
! O7 Q. C& i+ v, Y* S% R9.CSS多色边框. H/ ^. l. }( k* l4 u
CSS代码:. A4 U q" R+ F6 F% f# h: `
#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;
} 效果如下:* ^5 S: w3 Y& [, ]# c# O6 w; m+ a
|