CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。! k% O e% D k$ v
以下各特效用的HTML代码相同:$ \) Z% |; |+ o
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
6 @2 `& ^9 X8 {( e: s1. CSS动画边框
) {! G* S- y' V- w( o' O6 dCSS代码:
6 Y% h- d6 N# r5 x@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;
} 效果如下:$ O! M5 O7 d" d; Y4 `
7 B7 v- ]6 F: F
7 e2 f* O) A I3 \' J |0 W2. CSS图像边框
- d8 Y+ l+ i/ G5 d$ k7 ~2 `7 CCSS代码:
3 P* U8 T+ B; w#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;
} 效果如下: U/ W4 i5 T3 E9 ]
) z; \$ u) I3 L# g& L
* H; m2 }' W2 f3.CSS蛇式边框: [# M0 |( a4 o4 E
CSS代码:- }# j7 m2 x5 ^6 A N0 ~' }
#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;
} 效果如下:% I/ h: b; H# |2 a: C
! z5 i4 p; q; j3 J
2 r( l. w9 v# _/ _4.CSS阶梯样式边框
9 e( B! s3 o6 T8 t0 \+ h' X5 w& f7 pCSS代码:5 P3 H8 J4 \5 `9 y8 ?8 i) b" 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
} 效果如下:/ O( O% v$ d, p# A. L3 r9 M
H' Y# i6 s, I$ G+ r% Y
{0 C0 { O/ l
5.CSS只有阴影边框
4 p6 Q0 f. ?% D9 DCSS代码:1 V/ R: A5 i3 ~4 W$ ]7 e" Y# s2 C: ]
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:2 G/ Z$ }) z Q+ m
! a: B- Q4 b$ r9 o
3 z2 S+ ^, m2 G4 h- s
6.CSS带阴影和轮廓的边框8 ?: n; c/ C; Y& _- W0 G( X# |
CSS代码:
8 g& j1 E" _( n1 B#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;
} 效果如下:
) `# i' |" j$ r V; ]/ B. Q
, W- c+ v# b( w6 \5 V* R4 V1 L6 \" z5 M' O
7.CSS少量阴影和轮廓的边框, j+ m, [: S' d s4 D v# |
CSS代码:, ]; [" g8 x7 @* D5 E9 i
#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;
} 效果如下:2 Z. [6 C3 t! E# q- M3 g
5 p5 i9 K* @; [ B1 L; M% I" j7 A
! N/ v9 |( j G. t' H6 t( H4 I3 y8.CSS带有阴影的双边框) Z* A% g7 L6 b6 m; b3 b
CSS代码:
6 N( p1 V S. @# x7 ^#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;
} 效果如下:
- _. o6 c. r( T
# H* H, v, T# _6 I' W3 P7 ~
+ T! g4 \% `$ L1 k3 O9.CSS多色边框
. x+ P0 |1 J1 C" W$ w& u5 OCSS代码:
5 T1 k* J7 S+ b! k3 ^) g# [#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;
} 效果如下:
+ F( z& {+ ?! @' @+ F
|