CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。" ^0 D/ Z# n1 q
以下各特效用的HTML代码相同:
$ m# K9 ^6 h8 O" S# c/ K A<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
9 t% F2 c9 b+ F9 c1 |& B. |1. CSS动画边框+ c9 e1 _ l" o4 V+ p
CSS代码:6 u' M: w. N/ ]* ]/ f
@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;
} 效果如下:
7 b2 U, r0 R" n% T8 j2 C
1 n s( n4 v1 q; p( z! Q) E2 q9 i) T: q7 M$ h4 B+ x* d5 F
2. CSS图像边框. y3 w+ V1 ~3 A0 L! @- u' h
CSS代码:
2 |) W# Q& J l, _$ D; z#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;
} 效果如下:
1 v: R, V% a" o8 d8 I
- x1 e# X% T! d7 a# F! q9 G6 w1 _# _/ d1 C' _- g v* X
3.CSS蛇式边框
/ l) W$ k( T/ b2 ~CSS代码:
0 [& |0 g, p' {# \6 L3 A! d#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;
} 效果如下:3 a0 y7 Q( B9 y6 D7 J8 W, z0 ~; ~! E
a9 l% S' L' I9 B
7 [' B/ b3 c! d/ l" r9 C4.CSS阶梯样式边框' r1 R5 |# H- h! O+ P
CSS代码:% t+ P+ p: o4 q4 f( ~: q
#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 C# I0 V$ c. C+ K) e4 ?% e
( I( Z( Z( Y4 a( w, m: p& }1 m: M, O
5.CSS只有阴影边框) j$ {% I- O6 T n; N$ X0 x& x- c
CSS代码:
! J; k8 J+ }0 @3 U1 E T( `#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:; Q" G/ d7 F* O1 B h E: m. ` w! [
+ Y$ ~& H0 U, c9 J" X# J
6 a# y6 L: G/ y+ [# j( R6 z5 K6.CSS带阴影和轮廓的边框 H D0 c' k+ w* P6 _
CSS代码:- L8 q; i2 N' u
#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;
} 效果如下:3 B3 j' s B8 l3 s) X3 r
7 Q( m9 h( {9 u. ^" e/ Q' B5 w
6 G7 P3 s$ b6 b; y, b6 O
7.CSS少量阴影和轮廓的边框
% u6 s) K2 l ]3 z4 m3 zCSS代码:
! H0 ?. | J- X! W, s8 y4 ^#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;
} 效果如下:
9 Z. `& h; S1 \% ^) N2 p |) H) m
8 E) {5 } a: j/ x5 x: Q) J% }2 y8 A4 {' r5 I8 [
8.CSS带有阴影的双边框1 k. A9 Z- L( o( w4 J9 b
CSS代码:
& `* C6 q7 @ F8 x#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;
} 效果如下:% ~; Y: i% K4 i) N7 h; L
- V: I" U8 b. N. b5 L" M
' G3 h. _ r# I1 c
9.CSS多色边框" V1 G* X5 t5 l) E, T: q
CSS代码:
, h8 t+ o6 j5 P, d#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;
} 效果如下:7 S/ l _: r. @/ O2 c8 L9 O
|