CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。/ h1 G7 U5 A% h
以下各特效用的HTML代码相同:
( A% z2 V2 T1 B; T) f W0 @$ t" R<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
" g* @+ h; p; W% r1. CSS动画边框
* j" C8 c; o |* @! a2 lCSS代码:
9 K( Y# s i) n' ]% b@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;
} 效果如下:
* ^# ?/ K# x) c& U
+ I2 P. C f' u; ?: X! p
4 }5 S# B* o1 X! K& A: P2. CSS图像边框0 [$ Y9 J( s# P4 h+ a, F
CSS代码:3 Z3 @9 B( j! F9 W6 Q. z2 c$ _( ~
#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;
} 效果如下:
- K3 o: i, X8 @& Z8 w: d
; ` }1 X: F+ p
/ ?+ ?4 `- V8 ?0 ?+ B- w2 z3.CSS蛇式边框
4 M; i5 Q9 l+ Z* P, E* q& ?CSS代码:
) S8 I7 W* u& G5 n0 H#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;
} 效果如下:
" S2 V! f* Q% T1 r: G! s: f" s4 E
+ G' N7 [' w2 G0 A+ a
% V' m8 L2 B3 h) w u! R4.CSS阶梯样式边框
# E/ x4 k7 K6 |6 G/ ` |CSS代码:
9 d, S) P8 s) Y7 ^! d$ l+ |#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
} 效果如下:
$ k' H% D( u. J% |4 z
5 \- ~7 |* ~# |3 D5 R2 n# }/ B8 C9 @( E. Q, {! E) [1 o+ w: U! ?
5.CSS只有阴影边框
g- N6 d7 e- ]- m2 iCSS代码:! D" `+ x! ]/ y7 X6 G4 F
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
1 b# X0 ^) y! R% o W/ M" n
" x/ s9 b N) y# k# s# Z
# B$ {6 L5 y; H- v9 R6.CSS带阴影和轮廓的边框( p6 W, r8 M. [+ s4 y5 j# R
CSS代码:' }6 w7 M; h" ~: y, d+ }9 V. k
#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;
} 效果如下:
* o: A/ I, J& |: Y: a! ^
- w1 T4 ~3 l$ a- d
% ^6 U* }2 k1 `7 R) o9 S3 e7.CSS少量阴影和轮廓的边框
+ ?! G+ W O8 F7 RCSS代码:$ M& J- {% d" X1 f
#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;
} 效果如下:* r4 i G) w- B0 |: u4 _
$ g, G2 k. [. e4 m9 {! |$ r
1 q6 P) G D, Z! a. ?+ u6 r; m$ a; q
8.CSS带有阴影的双边框* y5 A) g: n z% U
CSS代码:. N3 x o4 w$ Y* H. R
#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;
} 效果如下:/ }8 V2 n" J1 I1 |5 @
( N. U) L* N# I: [* B ]
7 R$ g' J4 E5 ^9.CSS多色边框8 {& b2 s5 f) b9 H% h
CSS代码:
2 ~+ s+ ^/ N. {& \#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;
} 效果如下:
8 k& t7 z. c, K- s9 {
|