CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。4 a# A9 N" E% D, ]
以下各特效用的HTML代码相同:
, ]6 P' d% {- _% l N: l<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
3 ?% |# {$ s$ @. f4 X( {1. CSS动画边框
& [1 ?( n6 K' R( ]& [) [" zCSS代码:3 s8 j8 q" E# Z5 s. T# o: e$ m
@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;
} 效果如下:: U+ L$ W& t, m( T" b
4 A( ?3 @, ^9 Z; @) C# N5 W: m+ F* ~
- L0 s p% B0 y8 Z% U2. CSS图像边框
7 J2 ^1 N9 h, G0 ^2 S0 y& Z/ lCSS代码:
$ `3 r2 l- q9 U. Y. D$ M#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;
} 效果如下:
% X# m, D& V6 s- R* \4 j. J
6 t, l7 X& y- b0 ?9 X6 ]# m
1 i+ R1 r& ^8 \( j2 \4 @3.CSS蛇式边框+ H+ I' p; x' L6 @
CSS代码:
0 Z! W* ~! ?9 \" }: }#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;
} 效果如下:
6 z2 ?% F( I1 T) @7 j
6 s3 h3 Y' ^+ z. f A. ^
) i$ A2 C- W3 G4 {1 e" F( T4.CSS阶梯样式边框
( p4 F: F: H3 ~" {9 l+ ^CSS代码:6 p% M% {: h. D; 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
} 效果如下:1 Y8 D( d6 O6 f/ C) {! u
5 i9 R1 e* Y; S2 I2 i# V! I5 b& i3 e; s2 B
5.CSS只有阴影边框* r' |- m; D7 Z; ~
CSS代码:
2 v7 O B0 m* Y$ P( 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;
} 效果如下:5 r6 R7 t( t2 T
# C3 J. j7 U1 }% g- y2 t
! \/ ]' a& ? V) m! w3 s" ]6.CSS带阴影和轮廓的边框0 G0 I, a* O9 Y
CSS代码:
" I. p. h b9 |4 ^* E5 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;
} 效果如下:0 Z4 J; o! k% c; s
# }0 I& Z/ r f+ b; p
, r4 R" _2 b' C7.CSS少量阴影和轮廓的边框
' s0 T5 ?3 H7 i7 qCSS代码:+ E2 G1 F6 K) r/ _
#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;
} 效果如下:$ k/ K3 `5 e9 J3 t/ g, d* J4 r4 e2 E
' d7 M" h6 l6 h' L" A
0 w/ l& g0 u g6 S8 ^' c
8.CSS带有阴影的双边框
: \+ h0 t8 L" T) s) d$ i pCSS代码:) r/ t! q3 l3 y6 Y+ I8 f2 p
#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;
} 效果如下:( Z9 k' N# ^ q1 V! t0 q
5 A, U5 A) M! @7 g2 t9 G0 V5 t; U4 }% H* z. o; D
9.CSS多色边框* ^- Q" F5 c/ j; ]1 @- c3 y, s! x& p
CSS代码:; L6 |/ c7 Y: k9 V( Z \
#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;
} 效果如下:
/ A/ d& o; ~5 w; I3 `4 b
|