CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。 x/ B/ V8 T) z) G' S: p: P' ^; s
以下各特效用的HTML代码相同:
$ X$ H6 f' @' r' h7 ?<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> ! N, z5 C+ r) o* @2 v
1. CSS动画边框
- ~9 f) H+ W* I( z% G! ICSS代码:
1 P e3 y) j! M@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;
} 效果如下:
) \0 j2 N( U' t
; x( k$ @- o, ?, ~. U9 _
. @7 `9 I1 b" ~, ^
2. CSS图像边框; u2 t6 ?3 v3 m& k% I
CSS代码:1 Q D4 N% x0 k4 q; O3 w
#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$ N2 Z \4 e
2 e5 A6 j2 A* l
6 S. D+ ?" L: r# E3.CSS蛇式边框
5 I R: f8 @4 i$ N! R8 nCSS代码:! f3 ` Q* s& I$ S/ u; 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;
} 效果如下:
; b8 P) r0 w$ Z3 j) S
o; [+ S% m* m7 _( P
$ h' v# e; r7 k$ `/ r% I9 a4.CSS阶梯样式边框
* k$ M4 B% d, u3 J0 ^/ g% oCSS代码:# Z0 }0 r u8 H5 Y' ^
#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
} 效果如下:
" G- X+ n8 u5 h! o" R
/ N( b& v* K7 M6 G* @! \- [8 v5 V% o* s9 ]' i
5.CSS只有阴影边框
2 S& z" J3 X* ICSS代码:$ P$ }* N# ]1 z8 x" l
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
, H. b( P* l) ^- o* O6 J" G: W
- b/ T7 H: S) U: P
}" Z% w4 j7 H( \% x6.CSS带阴影和轮廓的边框
4 I9 v9 N! ~6 RCSS代码:
# Q$ g0 |6 V' c7 X#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 m' F& G* T3 R! x3 n
8 R, `$ c( C* p+ P1 O6 f. D/ Q
! w# H6 z: F$ u0 I1 H& U0 q2 c7.CSS少量阴影和轮廓的边框
" R Z* b, E, ~' }# t1 _8 \4 nCSS代码:. z( [, z2 I, z0 ^( F# a
#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 W% s$ Q( c5 q# x5 q! j# P7 K
* h8 M6 F/ h3 }
& B' _' A( E7 V# W7 c( e+ L
8.CSS带有阴影的双边框
, x8 [1 G; g; r T: u* t1 h pCSS代码:
; G* ]) ?! \: i, l# |#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;
} 效果如下:
( s H. K# e3 B7 u
$ L* P- U7 K8 q& H! c4 W. c
( _5 ^. |- g/ A& f( g1 q9.CSS多色边框
* c# ~% p# L" m {( |- c) PCSS代码:
~7 c v, p0 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;
} 效果如下:
+ V% `$ q( e' K% S4 r5 O9 l
|