CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。! X* E$ z5 B* d0 j8 o0 f
以下各特效用的HTML代码相同:
% B2 t- m, K* I5 Z' l<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 5 }' P' a, Q& k6 n# x+ x
1. CSS动画边框
9 j7 j* A: k2 ~9 O, s# O8 V8 gCSS代码:5 F" I$ |5 M0 D0 ]3 R
@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;
} 效果如下:
+ B Z; r8 x" a# m6 g% }3 ]
9 f" a9 C5 I6 x+ D
) ~ B2 p) {% r4 V
2. CSS图像边框
^3 a8 L4 H5 V. wCSS代码:6 q$ ^& Y2 k1 J" }; A6 I
#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;
} 效果如下:
2 x; G: q1 W' O7 b2 V; d
& P3 F+ T8 I" P0 n7 p J: f" m
1 `! b0 r) X: P5 z
3.CSS蛇式边框
; A& \, _ w9 R: V gCSS代码:* Y9 J7 i: m) Q" }% E' K# O8 a8 W
#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;
} 效果如下:
! \0 ` O+ _0 ?, t/ S, e
( B, b) v) l" Y. H) n2 P7 L* s9 t* `6 g8 C" M) m: s% ^3 [- [! [
4.CSS阶梯样式边框
6 `* J& m& X, R2 U0 u# X9 E. v$ u7 xCSS代码:) O; ` c) W9 F* V& _* v$ D
#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
} 效果如下:
, K \1 G( N/ }$ {, Y. ~9 \* L+ I* T
! F) S) _0 |" p( k; M' B5 S& b
' z$ ]3 A& m" ?# q, }5.CSS只有阴影边框2 o! T3 f5 ?* ^6 t. R9 A* }0 M
CSS代码:" }! {- S; j: @( 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;
} 效果如下:7 M) N, X7 m4 d& _% Q" u
' g" Q; R( T/ J( V* `3 H5 y4 r a, |0 |- w
6.CSS带阴影和轮廓的边框
/ S: d3 m. B+ a Q7 C- }+ _& CCSS代码:) {, c s7 y& {& O: \
#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;
} 效果如下:
4 t/ T1 y9 h& M ]& T3 ^
3 T, @) M6 G3 |& N+ E, u
?/ o' l- t: t5 |- l. b
7.CSS少量阴影和轮廓的边框
" j1 {' F6 F$ S! i2 ]$ eCSS代码:& K' u8 x4 w/ R U' i" l
#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 M# U8 P3 B' q/ p6 T9 U
/ g1 G7 d, {( {
8 @; p9 z9 B8 @- F8 t
8.CSS带有阴影的双边框# \; J/ r e6 f! b4 z9 N$ L
CSS代码:- o1 M7 U- i! ]1 A: u4 p
#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- d+ A. T2 Z( p
- C2 }5 @" o+ ~) o1 G* N# u4 `6 l( P( |
9.CSS多色边框
+ A. U+ ^; B+ K1 v8 t4 W7 pCSS代码:
9 A9 @, h2 m. I! M% S1 ~#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;
} 效果如下:& I' L- v9 b. y. t, W
|