CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
8 _+ f2 [+ r: L 以下各特效用的HTML代码相同:
2 c. c2 P% g' m$ M<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> + D: Y; o2 z( ^, n5 m+ D6 l4 p
1. CSS动画边框
/ Z+ U& m1 L$ j( M* b+ C( E' mCSS代码:2 W0 c3 V; t M
@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;
} 效果如下:
" |6 O1 i) E$ c0 x: W7 z3 j
9 P6 H# r7 q7 J% |# i1 Y8 n) O. C+ t5 X3 g3 w; Q9 D
2. CSS图像边框
5 a& K4 H+ X4 [: ~CSS代码:6 W3 V1 v1 U t- 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;
} 效果如下: a3 l5 n/ T, C" B. @
- O) W3 U+ @! r" `$ F+ B
4 \$ u# ]8 l7 k0 U+ X
3.CSS蛇式边框( p- `7 y& U$ k5 B& u( M- s
CSS代码:
( I: j3 V" t( A8 l% M#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;
} 效果如下:; w' m% x/ k7 n4 C8 U" O
- ^) ~ c) k2 o
' q; t9 \/ g" f" J, X) }; z4 t8 C4.CSS阶梯样式边框) x4 i2 L+ d! i* H+ \9 H# {
CSS代码:
1 l- A$ R5 {/ @( [4 A: Y#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
} 效果如下:
# ~# o8 {7 C2 v
: `& t# v* W6 X. M7 T; r
; q- J1 Z# _! {3 o; U* k
5.CSS只有阴影边框9 C5 ^- P1 r8 B% f6 i. W0 u' E
CSS代码:
7 e3 v* `6 `/ ]#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:5 f$ u- ^! _3 a( {% }8 }
# k7 J- T) m7 l, [" V; z# I
; ~: c6 C- U3 N- N6.CSS带阴影和轮廓的边框) x* K; }& W* [
CSS代码:
# S3 P n) ]4 h5 e% b3 h* m! J#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;
} 效果如下:
: |) ^' h1 U$ K* ]5 R! w4 n( W% h
7 M& M8 d/ t1 p/ ~8 N/ h& l
9 } U$ w. }5 f, d& _
7.CSS少量阴影和轮廓的边框
1 Q) V/ z. b. v3 {/ [CSS代码:% r$ {$ ^ z: `# e; @, Q
#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;
} 效果如下:
+ b. y& [ d% U. {' }6 p& P
8 W0 w9 U, z5 \% U: ~2 o: i( ]) e) Z* \% }4 D+ d2 ]
8.CSS带有阴影的双边框: V3 B6 t- ]$ k& A5 i
CSS代码:
: @8 k' @' _" f! z# Y* 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;
} 效果如下:
- Q' T" I( \. J' K+ b1 t' u
4 {$ L! W$ C7 Q) J$ s$ v o9 w
) b% h; ~% V6 ~/ z* o/ ~2 N
9.CSS多色边框& [% j* H0 Y o
CSS代码:6 q) a3 ?2 T8 s! ?
#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 C/ a, j2 H, o% z* k" g
|