CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。0 o# ^% P, d6 U3 S& p
以下各特效用的HTML代码相同:! G8 `! Y, \* G3 ]8 l6 c4 {, }
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> ; f+ v. y3 }) R# N+ B( q: G; u
1. CSS动画边框/ p: Q# g4 q+ x4 o- x" e
CSS代码:& {% N5 p- B: t [- q
@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;
} 效果如下:
+ ~5 V, m9 c8 ]* r
! N* w- N! |$ v9 m
6 i; V. g' \1 b; U
2. CSS图像边框; O/ k( Y0 ~8 C! K' n: g* z z) W0 f: A& ~
CSS代码:
4 V0 f7 N1 Y9 u) o1 W5 S#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;
} 效果如下:( e$ x! E9 ~: W/ \7 T d' _
( q- o) P/ h3 m: g! O/ b
$ @2 j' d' c, n5 r$ m3 V8 }3.CSS蛇式边框1 G7 D7 j! k0 b6 J# u& w* x9 E
CSS代码:
) b% q" u5 Y) T' J3 O- ^#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;
} 效果如下:
( l0 A e2 e) d7 d5 [
; s) C, Z6 M9 i* X
( i a( Z9 }2 f3 O+ h% f& q4.CSS阶梯样式边框- m* `6 @8 W3 l3 b* ]
CSS代码:' b- c% A/ p) q4 |; }# W0 m7 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
} 效果如下:
, K- Y9 |0 y0 `3 q2 N
+ p5 C( W) A! R# q5 w( d$ a
6 {) B- [; E @5.CSS只有阴影边框
' g! `9 B3 l0 T1 k3 R eCSS代码:
$ v Z; @9 D' H3 Z8 H* n4 A* U/ G#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:- d1 u: Z$ r" U
; j) X) r4 s: h- S! o% m
2 Z1 U7 n7 i! F2 q# ?3 U6.CSS带阴影和轮廓的边框8 Q ?1 ]+ x# S
CSS代码:
) G1 z$ C9 M& V. z#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;
} 效果如下:
- c8 b5 \4 `4 f8 A* u3 B
1 L/ x5 g* C0 ?, b
4 \; ]- W& o% F
7.CSS少量阴影和轮廓的边框
* D; M* |# X4 s8 X, d6 c0 rCSS代码:* c4 R6 r7 n& T3 |0 t/ ]
#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;
} 效果如下:
* V& m& h- N" d0 x1 Q6 i7 [* n
, N$ f' C5 ^3 t
! v( p5 D% _) ^4 i/ e1 ~9 @: T
8.CSS带有阴影的双边框
2 c" j& l X9 MCSS代码: F6 j* p) h0 T4 F( ?5 D% J
#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;
} 效果如下:0 [5 `6 ^! u+ q
/ Q, y3 u( Y' N6 `' X& a$ j- R) _
0 o+ Z5 H6 X% b+ u5 h+ p
9.CSS多色边框: X* i( n$ K2 O5 U, l7 C
CSS代码:! E$ m0 E1 M2 ?
#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;
} 效果如下: `9 `5 R% G- ?( j4 @
|