CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
" h3 A" _3 U8 c$ X9 Q 以下各特效用的HTML代码相同:( ^ M0 Z: g6 W) o
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
- e+ }7 I' ~7 B, ^& j5 D( t2 k% } a1. CSS动画边框
- n7 o4 `/ ~, a1 ^/ `" s8 `+ aCSS代码:
$ h& l% S( f% U# m9 S@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 k( f, g- M2 b) x$ y+ {& ^4 S
+ j8 `. \2 [' u( J
. @5 I2 \6 S* v6 k# l- q2. CSS图像边框 w0 l& J: Y* h3 H& m: O* ^
CSS代码: j# ^, ~9 o' 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;
} 效果如下:
5 K* n+ h; Y/ h, A$ e, z
7 K8 J2 u8 T. i, {3 \
) F6 Q5 W7 e$ \3 }$ G2 K2 E3.CSS蛇式边框; F2 M$ [9 q! D# C Y4 M
CSS代码:$ c* @' v! `2 D$ A9 t& @
#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;
} 效果如下:
- i% \! e* M% N' G3 M
9 [! ?3 _4 z7 S3 H; }' W3 b( A+ a3 ~8 X* |$ e% C
4.CSS阶梯样式边框
x+ n R# p- f. C3 gCSS代码:
: h* W: J' n! u#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
} 效果如下:4 N$ q, P( e1 k/ A. `8 F- T* K
! G3 |- g; c) y$ M1 L4 o# e
$ ^6 j+ s0 k1 P0 t5 m' m3 |% m5.CSS只有阴影边框( t' b) |& ?% r q* C, b
CSS代码:
8 S; H; Q; l; {- k' b1 w- d#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:/ ^( I$ B9 w$ K# g8 w2 E
4 S4 y! D0 |5 a$ H4 F1 a
0 {, `0 H- e5 b! X4 W0 }* _6.CSS带阴影和轮廓的边框. @* C' \9 s8 _
CSS代码:
! |6 m, `! [/ F#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;
} 效果如下:
7 N( K% Q7 F0 t6 M# N
( l& u0 L+ Q; D+ @/ W; o, Z' {8 F: f; s0 K
7.CSS少量阴影和轮廓的边框
3 S3 T3 G2 N# s* z# K |CSS代码:) n: L5 D& A$ A- w
#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;
} 效果如下:
5 }, G9 Y/ f; E u4 Q$ K
# k* e3 e8 G. O# ~+ p# t6 F2 ?5 Q c
8.CSS带有阴影的双边框0 Y+ Y0 t n- E# ~4 v9 V; z
CSS代码:- R; c2 x U$ }% J8 P. R
#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" J1 \9 I9 `
& }7 p: K8 e6 H; G" Q; q) \1 N
) s$ ~! F, |" |3 T- }+ j9.CSS多色边框
* V. m' Z6 n3 z9 x# K8 m" kCSS代码:
$ ^. s" l4 _4 b. {: v0 K& [#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;
} 效果如下:: j1 P+ p. v8 N. y- R% ~
|