CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。) f/ }. w# }7 C8 s+ ?8 _
以下各特效用的HTML代码相同:
% w2 m: K7 O6 b9 d0 c<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
& ^" _; Q- W% E- L7 l, S! l- h1. CSS动画边框$ R( W( Y3 \8 |' j- M- n
CSS代码:5 P# R# F4 Q" p0 t1 c3 [& \( Z
@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;
} 效果如下:
; B1 t- t. u$ X3 V. k' Q% X
5 H8 z8 I! J4 k
+ V( U* r2 d' S C" c; d2. CSS图像边框
. N- P* T6 H0 B" ~CSS代码:
$ ~0 J9 i6 h. R, [) y( p& Z#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;
} 效果如下:7 n! u6 B/ }/ ~, T; K% O
0 G) _' c+ t3 L- \
, n, l% l" _" n" k6 b$ g3.CSS蛇式边框
7 @) B. ^" N0 N8 }CSS代码:! i8 C# r; e! j
#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;
} 效果如下:, w& N( t/ M5 v: S
4 x% V' k' q/ ^
! M: z9 J5 K& G6 z& |4.CSS阶梯样式边框
w" ]6 K: p! a3 K k* NCSS代码:; C# s; E$ u9 c7 j9 a4 q+ i
#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
} 效果如下:6 t" K/ Z5 M$ L+ C
1 X! ] h; b$ R1 ?% Y, p$ v& f2 q
$ ]' x+ p: T' l$ Z; t
5.CSS只有阴影边框& b1 p! F. @" g0 L* i+ {
CSS代码:; E% p- r/ R& R' J# s2 S; e0 x2 u9 ~
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
, q' W M, S! o6 T' s' z
; l! d2 k$ e+ O2 L5 }/ Q6 a, P: I" V, z! {2 a9 U! f- O4 W
6.CSS带阴影和轮廓的边框
6 C8 z+ x2 c1 B+ c7 `CSS代码:" H9 \" M' M' K& l! ~. ~
#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;
} 效果如下:( X! ]- u0 d: Q+ S& k
+ r* C6 `8 O& K k. N
- r% B0 q) d6 o9 }! f* d6 Y3 g7.CSS少量阴影和轮廓的边框
) h1 o5 ]4 R" d: N3 S0 J# b5 @7 o) zCSS代码:
3 W/ B; v4 v, m# [, E6 _8 x#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;
} 效果如下:
$ u$ h, N' S6 |. A: \* g# l
3 I4 X1 o4 q& ^) n$ d
+ q, C) ?# X, Q: f5 O6 T! t8.CSS带有阴影的双边框
+ g; ~; Z9 Q/ f, J7 \5 T1 NCSS代码:: Q- ]) x v' u) r( E1 V5 C
#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;
} 效果如下:& I1 B2 V( Q) l
6 a2 S. y5 G' T) u* ^
8 v. x( \+ k/ H7 S/ ~
9.CSS多色边框
) P9 V1 ^ ]+ u; B+ m2 Z5 \CSS代码:
' @3 C1 L: _1 A1 \) a. [#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;
} 效果如下:# L7 g6 N8 }0 t( X2 K8 u& t
|