CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
( u7 G! T e0 P; o2 J, F 以下各特效用的HTML代码相同:
5 O& K7 h( S# ]' P<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 7 [* e9 H0 k9 q) m8 u- j
1. CSS动画边框+ d8 }4 T; e9 o9 r) s
CSS代码:& s2 l, ]; e8 W2 u
@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;
} 效果如下:
) Q! d$ L+ U2 k: f0 v& u! j
, {% Z/ [; G9 B; y1 X$ S: Z
: h3 D4 N# U) {% p5 t
2. CSS图像边框% |) m# e7 h4 |( |' t
CSS代码:4 B+ J6 _! R1 ^9 F6 U8 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;
} 效果如下:# ~6 v8 Z4 g8 \/ @' L! ^ Q0 P3 P7 Q, z# @
" _! u. V5 j t1 @, w
0 W& [$ n0 M: [3.CSS蛇式边框: ~; w, ?- t- q R
CSS代码:' P5 @% Y/ b* {) 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;
} 效果如下:/ {$ A2 {/ Q4 t& X2 r) ]" ~
% M( U2 V% l, a" A4 v& C) E- m$ P, V" [$ }1 _# V' s8 s
4.CSS阶梯样式边框
$ [; k. d$ x, m; f5 cCSS代码:% ?8 W a9 `0 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
} 效果如下:4 U4 ?2 \: h5 i1 P- Q% V" h( Y' N
+ r3 R8 l3 _# O1 ]: _$ n, J7 |1 {, F/ J5 K5 e, Z
5.CSS只有阴影边框
" Q8 u( T% K2 \% `0 f5 e/ t; B# {CSS代码:
! ]+ L6 R* _8 o& d1 k; _$ t' m#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 k( i7 `4 G I0 v. j. ?7 I
, \" u& h5 b+ I& ]% n' |; s6 W. Y C: f \
6.CSS带阴影和轮廓的边框
2 S2 x" Q% \: q0 uCSS代码:1 E' _, j8 b; r' U5 w
#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;
} 效果如下:7 C4 W- l6 f6 X$ ^1 g8 y
2 B# r+ `! Q7 d L
4 e, `1 s) o3 @% d
7.CSS少量阴影和轮廓的边框
. `9 J8 R2 F. S* Y! _' YCSS代码:
% g! l! B4 S. T1 K6 m#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 B. @7 s$ P' S, J+ W& P8 ?
) u1 Q- Z4 F# }+ h8 T$ r- o/ l% h) _% F# @5 {2 P
8.CSS带有阴影的双边框8 g7 ^1 h+ V/ Z4 v- h8 t- }
CSS代码:
. d( W& n2 }5 B: G2 W#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;
} 效果如下:# I( M) J7 e+ {; Q4 d
% I& e8 U% f% G
, d0 J& D3 L% M$ `6 y. n& E9.CSS多色边框
( ]$ b% K8 u% ^5 h7 WCSS代码:# B# U# f9 o6 v: B
#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;
} 效果如下:
/ X& q$ n, ^. f& h
|