CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。/ Q' t# ^1 K- g. P/ s& Q$ T
以下各特效用的HTML代码相同:% w2 q6 E: S. m- Y |
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
0 h+ R, j- R: E* T' e
1. CSS动画边框
& @$ d; s2 W5 l) ^8 p+ w- w CSS代码:
/ @3 W2 z3 E0 ` @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;
}
效果如下:% I4 W4 _; A& a: ^0 j6 ]
( G0 ?. u3 t- O" @6 }2 S : o" k! C0 f' U3 C( s4 E5 e. ]
2. CSS图像边框
& j' P, m) \6 A* U4 s/ z1 j! s, y CSS代码:
, G6 Y, x# }$ [* U #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;
}
效果如下:
& d- {' n' G. ~0 U& ]2 e/ o* S `
. l: ^& a) O" q/ e$ u# d; Z
* C4 k+ N" j. ]! `4 l- g 3.CSS蛇式边框 ) x2 S3 P. I, h H4 V+ v
CSS代码:
) a4 Z7 A5 X R( g; Y #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;
}
效果如下:; z7 ^' n. ]* m4 ]" v0 B
; B, _- }& U$ b4 s+ K* j. p) x, D/ i& M
6 i. u4 T* t6 V6 j8 j) t 4.CSS阶梯样式边框
( J+ Z% I) e: j( ]: _- l; c CSS代码:; e8 k# n4 `$ {& a6 G; Y+ Z, o
#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
}
效果如下:
$ M- D4 U6 q M/ N6 o
* q% {& h% g, \) G0 Q4 S ; V N$ D6 C. \5 Y; O( u8 z# `
5.CSS只有阴影边框
* Q- e+ B: p9 u9 k5 S CSS代码:
s6 G! L3 g7 a! E) [ #box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
}
效果如下:
: H! {# F7 I& h& d2 g+ q' p
, }8 a3 O& M' J
- Q5 q m- W, m1 i7 a/ [& U0 j) f- z& h
6.CSS带阴影和轮廓的边框
2 ?0 Z4 i- F5 p" G: } CSS代码:' g: n7 E; m# C5 S, I; ?7 i
#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;
}
效果如下:
% }/ k$ g" J+ E8 d, B4 I! p
% ^ L$ J& m6 s; O
- V. s+ \. [9 b! j' C& L" y 7.CSS少量阴影和轮廓的边框
9 k2 F% ]* Z! F( ]2 ~ CSS代码:3 X2 X3 T% ~0 ?, I8 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;
}
效果如下:
$ e8 s, F# x$ K \0 b5 K! r
! U$ n0 c6 Y* p
* v( n% \) I( y& q6 I 8.CSS带有阴影的双边框 8 W$ O5 X9 J' e* i( T
CSS代码:. O# U! C: o8 W1 j% o7 O# f
#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;
}
效果如下:; {" @+ J# \; W" U8 W) F% ?
) f1 m' j: B9 O
" M" ]) z& Y$ A1 z* o7 @& r
9.CSS多色边框
" Z* j* \2 b: J. p0 I CSS代码:
7 A" c6 S# n! T% X9 B% O #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 }! E8 u7 B# \, c