CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
& b3 F; h) r) W 以下各特效用的HTML代码相同:
; Z: g0 _2 q j% z/ y" f<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
# L% T# U. |4 s( r, b1. CSS动画边框
) [( {8 @4 d5 K- g* V rCSS代码:
4 {! W( b% O% E& k: a@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;
} 效果如下:& t: ?" r* m; E1 M; p
5 n Y# B6 @$ _( K- f x
: ^. j' c1 R/ M1 ?: l g
2. CSS图像边框/ P3 Y* w/ k) g1 f: P
CSS代码:
# ?; G" @3 a/ B8 L# a# _9 n+ s7 G#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 \+ f6 H9 L( m
+ I0 L6 S$ g0 }
* i+ a. ?6 u% d" [- t' u$ k2 K
3.CSS蛇式边框+ G! a/ A2 D$ s
CSS代码:' C. C# l1 R3 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;
} 效果如下:5 C# W8 |+ K3 ~
8 ]- y( Q$ ~& X) H" Z
! k7 H: Y( D& [
4.CSS阶梯样式边框
8 @8 t3 J1 g7 t3 l0 F$ dCSS代码:
9 \# K, F7 n3 @ S8 q; e#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
} 效果如下:- s" p: V! o/ x
& ^4 J% B$ Y# V. H( {. z7 ` X
6 \9 |7 D% {3 U( [5.CSS只有阴影边框- U" F+ z, e# X# }
CSS代码:
) L( K9 F6 v9 u6 Y' W2 O: v#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
. Y2 ]- X) M0 a
; y+ A s% ]5 L n! C+ q1 f4 {
+ }( H/ V$ L7 d. V6.CSS带阴影和轮廓的边框
7 t! h4 k% }9 t2 D" t: f# ZCSS代码:
- h% |7 e5 e8 x) O/ 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;
} 效果如下:
+ T6 \, A* W: v: {' g
. y3 {: c( l1 g
; o' Q" f3 Q2 y
7.CSS少量阴影和轮廓的边框
0 T5 g" D3 }5 Q$ d/ H, sCSS代码:/ A" k/ Q" f7 C+ [+ n
#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;
} 效果如下:$ G/ l9 U; J7 o9 D$ U) o6 T7 i
( K$ S0 m1 J9 k+ b7 G
' u/ I- {7 U) B' u' u2 s" r8.CSS带有阴影的双边框
/ g; Z! t8 L$ H: U7 TCSS代码:9 R+ t& h' R X0 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;
} 效果如下:
+ t$ ?6 @1 i4 _5 }2 L
$ n$ d- o N/ j4 I9 y3 a0 j* G
3 I* u/ i0 N0 _9 s9.CSS多色边框
) d. T; p A/ o# b7 k; O- mCSS代码:/ S* v' [* K( g" w) Q f: 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;
} 效果如下:+ d. S+ s# l( B: D4 \ @( D! a
|