CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。# n" D& U1 j+ b3 H" e9 ?6 w9 W
以下各特效用的HTML代码相同: ]/ w. y" W- G" z% R' \
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>9 n; T8 N: T$ a9 v5 |
1. CSS动画边框
# O5 Q5 F+ R! C0 } CSS代码: @2 |: f% U9 Y" w O
@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;
} 效果如下:: ^' V1 ` K7 j8 K
) D! F; A$ \' z) X% e0 S
2 u8 C( j9 c& {+ i 2. CSS图像边框
* y( p1 F s# {/ X4 R CSS代码:
/ ^, e" c7 s) I$ c0 k #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;
} 效果如下:; L) T/ S P$ \( N/ ^- ]+ X4 I
: w4 M4 G4 ^, ?) D( r+ d
) \" ^' h. |$ u+ L 3.CSS蛇式边框 # Q# I# Y" l3 I
CSS代码:
/ m8 D- @( b& C4 Y$ s. y2 P* ~" \3 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;
} 效果如下:
1 P% R' v9 ]9 \7 P) q
- ]7 L' s, r1 C9 O. }9 @( Q& l3 p9 d
|/ m# T2 |. c 4.CSS阶梯样式边框 9 h& c; i( H, `! T* W
CSS代码:
, f4 u. x3 \6 Q+ Y, P #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
} 效果如下:
8 D3 [* f8 q& k8 u! j, B
& U. ?# N8 e9 G+ Q
+ {9 G: U- @4 J8 l3 k 5.CSS只有阴影边框
4 K" k5 w/ m$ T' r4 |9 A CSS代码:, R) g# e6 N7 k. o" k7 I
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
8 F+ F9 O# ~& z2 a
4 o6 Y% Y* F. w: H( N& Z# g0 b$ M # Y( B+ A, ?5 m1 i, U+ b
6.CSS带阴影和轮廓的边框 1 g2 a. v, b. H/ ~+ ?$ ^
CSS代码:6 ~( g. _2 B$ S' a, s! o8 V. Y
#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;
} 效果如下:0 A% g# a. ~6 v2 o; K
- |8 f9 r% g/ _& y; u
7 j. U; E" \% V ] 7.CSS少量阴影和轮廓的边框 3 ]5 A5 I* d: C! ]: w
CSS代码:
8 s4 K) U& f! `9 s #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;
} 效果如下:
& A, D; j& `, i' ]! q& u
T/ M% `! H$ _8 Y * d/ y6 k% T+ c7 F ~7 c" h- a
8.CSS带有阴影的双边框
1 v/ B7 Q+ n4 \ CSS代码:# U8 o, C; X m; 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;
} 效果如下:
' D' Q @# E5 _# _. ]0 | ^
- }/ ?. A- R2 R
& f2 [0 U/ l1 x" j; C 9.CSS多色边框
/ Z: w% C2 f& D0 d; U CSS代码:8 Y4 C/ V3 G7 C K( y3 J
#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;
} 效果如下:
: H. r+ U8 w4 M- M