CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。0 i" `9 A. T" [: R
以下各特效用的HTML代码相同:9 @% N- L G/ N, U6 W% j. Z: B* M3 w
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
) p, a* A; ]- G. Z- f6 U; Y3 P1. CSS动画边框
" R7 S: s1 Q- ^8 Q' l6 x% H$ k3 q# R* rCSS代码:
0 ?4 q. ?; G* u. W$ w@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;
} 效果如下:% d: O8 @7 K! h3 U' r. Y {
+ ]3 U! E9 p, c6 m, `
+ `4 k' |4 l/ `2. CSS图像边框
+ y: [, Z/ Z% m4 Q- P8 n2 TCSS代码:/ g1 y2 ? Q: l" c# i
#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;
} 效果如下:
0 r6 D3 m4 O* P1 r, w
& X) ?" h% E2 f" z, K7 D- O
! s4 n6 K5 }8 F0 O6 j2 j
3.CSS蛇式边框
! b$ Z2 z# c" ?$ L+ X# Q, e" G4 K; \CSS代码:
N. W4 k0 x: l0 ~#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;
} 效果如下:( ?8 x$ P; x1 P* l, B1 S3 A, O
2 @+ f/ D) g2 H# O) S8 S5 F' Q( b- k- K! p
4.CSS阶梯样式边框2 [ Q( h. q1 w6 Z* i; j2 x
CSS代码:' s6 [7 J% {3 m& |
#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
} 效果如下:- d% Z0 B+ y8 ~/ R, R9 N, \5 B
# M; J1 i5 J- {
- K0 v" @% Z2 J; V7 u5.CSS只有阴影边框0 ~* X+ R0 Q E. m& T% ?
CSS代码:2 o1 C9 }* C1 p+ s. D! P% p/ B
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:- V# w/ p8 B' H1 u6 {/ ?
# K( \; w: a! ^" t t; X
( v! x8 b3 [) m: P6.CSS带阴影和轮廓的边框
; x8 |7 a- F0 C6 f2 C3 b8 ^CSS代码:. p5 R: F0 P; q! W3 M/ C
#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 ?5 @. }! ~( b: Y, y: y6 H
3 K# |0 j) d2 q2 Q; F# J
# s$ ^8 M" k) ^# f0 j6 G+ a9 d
7.CSS少量阴影和轮廓的边框$ w$ [& R! X* n4 e
CSS代码:
/ \* j* i5 @: Q: C* ]" @#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;
} 效果如下:
1 x' d" ^$ I! q4 M6 J1 S) P
/ p7 `9 i) v' j2 g
& w, ^) M& K- M- s! @6 x8.CSS带有阴影的双边框
; X! N, {. V) s' p0 D( _+ PCSS代码:" G: k! y$ U) |
#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;
} 效果如下:' m1 ^* |, S( z
8 O2 X5 b. m: |* Z# I. { r8 b2 r! O p6 M# I: v4 ~9 T
9.CSS多色边框
; ~/ X1 `6 W. {: lCSS代码:1 S3 K3 S T. h2 ~6 o2 d' W
#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;
} 效果如下:
. i. V$ ?' T. ?* Z
|