CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
- K. \* e0 r) w6 L8 C' C 以下各特效用的HTML代码相同:
7 S5 {/ B1 C3 p' H% ~# p<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> & S, Y' I: w( Z& t! J9 L
1. CSS动画边框
6 Q, H( @, ^4 l- P/ ]CSS代码:, G) ^+ w+ C. y( }" c
@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;
} 效果如下:
' p" C) `% c6 y9 s$ }
. x& A# ?2 h6 t3 o
7 i% h3 f& I! M/ Z* d* {, i2. CSS图像边框
$ q/ _, C7 V8 E$ ZCSS代码:/ [ R) c; k( o. X
#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;
} 效果如下:- q2 |8 W/ y- e, w8 C
( G& ], k; h* [. ^
' q, D" d; h& ?. ?) S( m3.CSS蛇式边框+ W% J# R4 N3 _; J" a |( Y
CSS代码:
* W3 D, d! m* g) n+ |6 ]#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;
} 效果如下:" [, ^" j) \. o# o! D& [2 ?8 Z
7 {$ N8 i6 D2 g) A3 g7 R% ]8 Q
. i( n6 H6 d+ H3 ?1 m+ ^) P4.CSS阶梯样式边框. }8 b3 \2 Z/ w2 b4 n
CSS代码:
- P8 \0 W* e3 ?) p% 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
} 效果如下:3 x% A' ]+ |0 D+ h
* D" @2 E, j! j( ^
. ~/ i2 d- h; B5 N' H) o9 y3 _" V
5.CSS只有阴影边框9 z# t V0 u3 ?4 N3 t) U
CSS代码:" F2 _/ K3 [ w" o
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:" E0 J, z2 u" A8 K* d- P
( T, |6 U3 Q* z
! _# _2 @) i+ I2 ]! V. i/ c4 \
6.CSS带阴影和轮廓的边框
. [9 m: d# W( m% \2 b0 [2 A# mCSS代码:
8 \/ Q; w; k4 ~$ P; o#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;
} 效果如下:
9 X% y8 V' N" S. w
6 ?' @, L; t2 C9 l0 u
8 m0 E! r4 r% W9 R2 h4 ]% q( F7.CSS少量阴影和轮廓的边框
& N0 x1 ?1 d% S; F: V, ACSS代码:
! p3 @. }9 B9 N' {; j#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;
} 效果如下: V0 h4 }# ?8 R( u" y7 J
( o9 L( h* y# G2 \( L* B4 F# G' f0 w% o2 P& W/ [
8.CSS带有阴影的双边框% r4 p2 B4 B. e0 v6 X
CSS代码:" t; v& h8 h1 X
#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;
} 效果如下:; x' L5 H4 E: m7 r+ u
: N6 w& u" `9 K q7 m2 M) w* q" D1 p
6 C' x/ _) F$ q- Y! q2 q5 t
9.CSS多色边框: W& @) X% Z) _1 e2 z+ n2 ^
CSS代码:
! T: |, G6 Q5 Z$ G& M' 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;
} 效果如下:: m) m: T9 e: R. f3 E! j. B
|