CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。. @0 i9 Y9 {* J
以下各特效用的HTML代码相同:
4 y! Q/ B; g0 i' q<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
; c8 U! U1 s1 W9 F) l! i' |8 S1. CSS动画边框; ~# U/ J) U- r/ U6 T
CSS代码: }, E( c4 J6 q4 G+ S) T
@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;
} 效果如下:
, o! g& e+ Y |% u! z+ E, Z
. g i# O6 Y* H' s# v5 i
$ c4 _! d% j' H$ ^* X: A2. CSS图像边框& z# a2 O. t' s4 k0 K2 ]) B
CSS代码:
) X- \6 g E. D1 B$ r( 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;
} 效果如下:
, J4 G# e6 x2 e1 _- v4 F
5 D) y' j( _% _% E- ^
3 i7 {- _4 _ ]5 ^3 I6 s. T- B) m0 j
3.CSS蛇式边框
/ z. q$ G4 K" l' s5 @CSS代码:8 c; [- E" |. D8 F
#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;
} 效果如下:
( Y+ T5 @1 n. \. y5 p
5 U- E2 v; S) F- C1 q8 H( {& I
- g3 u0 c% R; y8 j) m+ i! W8 x
4.CSS阶梯样式边框% c3 x9 I2 h: }9 U0 V
CSS代码:
& U" T* _+ J' o; r( q* t+ Z#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 f! Q7 q1 E, s* c0 r2 m
2 p5 P3 o8 {8 K3 c, n
g6 d$ [; n; n* j. N/ f- V5.CSS只有阴影边框$ t* z4 ]6 u4 }
CSS代码:
, S" U+ S b" O; Q8 @ P- 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;
} 效果如下:
- V. X% @' n) ~
* V' m1 i1 E# i' m3 Y1 M
! ]) l1 Y2 _2 r+ ?# L9 O3 a: a6.CSS带阴影和轮廓的边框1 Q* g( m& T- r0 }& S" g
CSS代码:
" \+ T+ r. C1 y( c1 `#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;
} 效果如下:- h" |: z, S1 k+ g! {+ h
! B' Q& B. _- [8 I8 P- Z! [/ k/ a
' h' n2 Q b, ~6 g4 |
7.CSS少量阴影和轮廓的边框
7 ]2 U6 f! {" Z7 |! L( G1 MCSS代码:
/ w, O. H$ d' V8 l' `#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;
} 效果如下:
: y! D3 J! m% L9 Q; J" @
9 Z& X: P: c2 E7 n. \
/ U I: I6 T; ^/ q
8.CSS带有阴影的双边框5 R- _$ u- h4 k0 n9 Y
CSS代码:
n1 H' a9 C X/ O#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 m# X1 G9 `: k3 H1 f
, ?, O+ @& g" ?
* E! P9 h2 ^+ {# v8 u! n$ m4 P9.CSS多色边框; l7 [: r/ D* F
CSS代码:& R. `# I* F: C$ d% g) |) X# P
#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;
} 效果如下:
$ P9 e& C4 A; d# _$ B
|