CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。# f& Z1 H& Q* N; }4 P5 p' n8 L* s
以下各特效用的HTML代码相同:
/ q! B- }" }' \4 J) D0 w<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
' L( S5 e5 t+ w1. CSS动画边框
: c( O' k b9 x1 U. Z: Q2 W$ ZCSS代码:
9 |1 a. T* A1 N$ |" i@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;
} 效果如下:
: q% O" g! d% `$ M5 M% s4 Y
/ c9 `7 n" z. {2 z% C
' Z" {* o* r) J, M) `
2. CSS图像边框3 v- c8 J$ J% q; H6 [
CSS代码:
6 {. K" i; Z" a) D#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;
} 效果如下:
# b6 f6 b4 P, V
8 I9 z! f$ q! E9 ]. `* q
, [/ e, Z7 f- ?+ G+ t0 b/ w3 Q3.CSS蛇式边框
8 E3 N/ G. t) `, {( `CSS代码:/ H3 F( L) K: w, N
#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;
} 效果如下:0 L* Q* H( A& j8 W: f. F% W
2 b3 f+ a# E2 ?7 x
/ \+ A7 C& p* ]: t4.CSS阶梯样式边框
2 j+ O @/ D! G# {6 U# O( uCSS代码:9 X/ |2 c% C! `- E( L2 S
#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
} 效果如下:
: b' f/ L) [; w% v; ~. R2 `
3 w/ ^ K0 h# d
; |: L0 }9 v" K5 V
5.CSS只有阴影边框8 `2 X! R6 r4 n& @0 A
CSS代码:1 `5 Y" H1 G& i; A
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
, w* Q) W* O9 _: W: ~% o* V: @
+ k1 u4 U8 k' {; x7 C0 c
+ x! A0 r0 c8 y& `6 K, w0 c6.CSS带阴影和轮廓的边框, ?0 Q7 i- G5 K" W& ^7 q# J
CSS代码:( t$ r/ y: k7 g) T2 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;
} 效果如下:
8 p# e8 ~3 A3 h
$ W# F2 W: Q$ h% J; o9 w2 S% S" p/ ~
P+ h. M- D( ]1 `7.CSS少量阴影和轮廓的边框
( i2 x4 n+ \# G: I* M6 g, Q8 tCSS代码:
0 ]1 A7 l, ]- b3 t) Z% l( I, j: l#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;
} 效果如下:" ` h) T/ e! H# }# h9 @
% B1 V7 H- G/ h, U5 K2 u
8 Y" W( f+ a0 d" N! l
8.CSS带有阴影的双边框
( H# @# G0 ]# uCSS代码:
7 D9 A- P1 H" T/ T8 r) G& X& _, K#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;
} 效果如下:
, H6 h& O/ g9 G1 j1 I
( ~. V6 K3 K- f2 ]3 Q+ [' k' ~: F
; K4 C. Y8 J0 o! E7 a0 Q
9.CSS多色边框
`1 {; [. a+ V" `' e0 d8 FCSS代码:
5 S* ?7 N3 h* x+ u: v9 U7 O#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;
} 效果如下:: C, I b5 v; Q1 \+ c" U
|