CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。 k- e0 N+ A; {1 T; C) O3 m) V
以下各特效用的HTML代码相同:
* Y: S% P, C9 h- _<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
+ m& o! G. b, b0 ]1. CSS动画边框
& E, Z. \: T# wCSS代码: R5 n2 \3 Y! N8 t9 G
@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;
} 效果如下:% c0 f7 |5 d; f) D
3 j% O, @4 Y* S
: G V0 O& I7 m0 i* s; u) f+ u" R" W& O2. CSS图像边框% L+ y5 j+ u V6 D
CSS代码:
+ F& U) g* g0 H1 Z4 B 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;
} 效果如下:8 t; N- {! t }5 a% G
! V' }, w$ l" [5 u' h2 l) i b
/ R& F1 g' c+ y$ n3 ~1 Z- N
3.CSS蛇式边框
3 Z; ]) e. n; h8 N- |9 v2 gCSS代码:' B# F/ _) z% w- h( a
#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;
} 效果如下:
+ k$ v( v: A4 U1 o2 s/ L
% ]1 o7 a3 D% N4 Z/ o
% S. r- U2 O7 Y9 t' [' s0 W, ]4.CSS阶梯样式边框9 m; _$ ^# h9 a7 f- A& y6 D+ E: k5 {9 [
CSS代码:% t7 w1 H8 u1 H5 R0 r
#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
} 效果如下:( C) s. N1 W/ `
, j3 q- L- z* A
5 G9 q/ j) n; B
5.CSS只有阴影边框! N) t1 E/ J7 k
CSS代码:
, u1 ?4 N% C- K8 J' g, 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;
} 效果如下:
5 j2 I: V/ c! X
( p M2 h0 l' O" ^& q* p# r& u4 N( M% t% l
6.CSS带阴影和轮廓的边框4 x: d$ V" B R; p* I* A0 ~
CSS代码:: x1 T0 x9 B) }! D
#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;
} 效果如下:# a: q1 T: W- n# }+ s# {7 P9 a
- y( m/ z% m! q7 m/ S9 u$ x# p+ y$ d2 W4 z& E6 f4 M$ l
7.CSS少量阴影和轮廓的边框
5 H' L. z- f5 i# H% X+ ICSS代码:
* F& n' x N* i, m8 T, |#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;
} 效果如下:1 K0 t8 J8 E; |1 t9 @ Z$ O- v. b
4 e, Y( T3 K1 E% c+ f, I
# ^/ Z( D4 ?- U6 \3 F& v! B8.CSS带有阴影的双边框
6 U7 ], h- k9 E7 d. [8 lCSS代码:
/ t U& Q' k6 [9 O4 G7 @. u#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;
} 效果如下:8 r' L" P, t- h+ _9 E- _1 ?
" Y! j* s7 n8 {$ E9 U1 l6 V1 A, G9 q/ r2 v
9.CSS多色边框
- F" A7 Y& V% O5 D4 uCSS代码:6 P$ `5 [4 l- @" z) w
#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 s3 }4 v, X6 R$ s# ?* c
|