CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。& Y& `- k* l6 w7 l
以下各特效用的HTML代码相同:& j* q9 R* u. |6 X* M1 v
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
5 a. s x4 |# e. Y6 ] 1. CSS动画边框 / l2 x! l; R- r4 n. A
CSS代码:5 b$ s3 i: \5 G z
@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;
} 效果如下:
# a+ @6 J5 _ f
% ~: g# s; _$ X2 [- ]9 ]
( h. a. E# h- c, ?; u 2. CSS图像边框
+ G! \7 W) A K) ?% c9 I CSS代码:. ?( V. ~% |5 C+ o: J
#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;
} 效果如下:/ b8 W& ?. W R/ @) [' q* q2 e
, x# j3 L {2 }+ D6 J3 |$ g/ v& u
5 ?" u, @! ?9 N6 O- n( z
3.CSS蛇式边框 ' Q( L7 L4 k' q/ h& m6 Z. b
CSS代码:! C/ U0 c! A2 P; h- s
#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;
} 效果如下:! q. j3 |$ J" ?; l- |8 @
; e! h5 s' K7 V6 J- f0 l) }
2 P y7 { R/ N3 J: m 4.CSS阶梯样式边框
0 k; C! |! M# n' G- \% s f1 e CSS代码:
& F8 `: J% t/ G/ x% M/ s1 e #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
} 效果如下:0 ^1 K" x9 [2 b7 ~4 M3 u
2 N- c- v b" L( h7 N! @
/ H' l1 p7 I+ `5 j0 K 5.CSS只有阴影边框 : D. m0 G$ P+ p; e" V) [
CSS代码:
% u5 |1 d/ `0 R1 r$ ? #box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
; E9 c9 `# M. r: O7 N8 L# Q V
: g! V7 I- v6 C- C' ]8 @
- \$ T: `( r' V* i! \ 6.CSS带阴影和轮廓的边框 8 t( `7 w' L0 T, x/ p$ q
CSS代码:
" t- B2 K% L+ @2 [- a #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;
} 效果如下:
. g4 @+ R6 }$ }. ~/ U1 j
3 E H: s( }( P+ T2 I+ S
$ X/ R3 w) K& \4 L4 _1 f2 f; _ 7.CSS少量阴影和轮廓的边框
" y B6 E( E* N- ? CSS代码:7 A& i5 M. D# V, S
#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;
} 效果如下:
6 n' g y4 }& J2 i
- l: n4 x& W9 I9 P/ s- e) x; h " d; Q5 w/ ^) ^5 R0 }7 \" \
8.CSS带有阴影的双边框 1 s: y6 p$ p. x% n/ r3 D: K
CSS代码:1 {) Z, P8 E% d" ^2 l# \+ |. d
#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;
} 效果如下:' C1 I [0 h0 |7 r8 ?/ @+ }
/ J5 q" R4 @; p- ^; a. a: c7 s
6 b2 b, M+ h' ?9 | 9.CSS多色边框 2 v4 K. M; v- g2 J$ v; k6 p
CSS代码:
2 E8 H- e* D6 w5 i' q" u #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;
} 效果如下:2 `& R0 W6 ?0 y. o4 T