CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。7 P8 G- s: S: O: `
以下各特效用的HTML代码相同:8 j( \2 M3 R" [* I z G2 F2 X
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 0 _0 Q2 K L. y
1. CSS动画边框* v5 C0 z: K$ E) b
CSS代码:
# X1 `3 R; M, P2 ~8 j@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;
} 效果如下:. p8 j0 Z, J& K& T
: i% H- z* j; x- ^7 _
8 H3 u/ ?/ E* ~6 ?2 C) |* Y2. CSS图像边框
. p8 \3 {) G3 @1 H# [8 e# K) wCSS代码:. D' M- U% Y1 N- A
#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;
} 效果如下:3 y' c+ w9 l+ J( [, Q
) X+ x: |5 `2 R6 y0 M8 i8 Q* } D6 G; q- P
3.CSS蛇式边框( B' A0 j% T& F/ J: T9 T; |7 }( I
CSS代码:
# C0 b7 `4 ~1 x: m- v8 C2 W: V#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;
} 效果如下:
- E0 Q6 e1 ^2 x$ J' ]# Z, y
$ b g; N; q6 l9 Y8 f
6 X3 }7 `* u) i* c9 q2 c4.CSS阶梯样式边框
) R( D* b- Z( ` Q% r5 D7 S$ WCSS代码:
0 k a/ n1 n b7 q/ ^# c* C& N7 ?#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
} 效果如下:
+ F3 n" @9 q9 \8 D+ w h% J9 b: h; [
& G {9 r8 u5 F$ ?
c5 _3 y+ A9 Y* E5.CSS只有阴影边框
, ?9 L& z3 U- p/ T# z! j) WCSS代码:! ]' [% ?, j# u4 c. G
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:2 [/ l. j1 }. A: }3 l- h. z9 K
; p; ~8 b% I. [: r
_. F N1 i; e! S6 C6.CSS带阴影和轮廓的边框; I4 C( M; k* Y1 K
CSS代码:
/ f% M3 ^! E( @& R' O, r/ U#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;
} 效果如下:
" ]( n! q6 p5 J8 d* i5 v! Q6 K- d8 A
: {* b1 Z. F, P) z2 f7 p1 `* S5 Q3 O) L5 B: M: b J5 f8 J5 s
7.CSS少量阴影和轮廓的边框" K5 E- G( F* I
CSS代码:
8 w2 j5 Y7 ?; 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;
} 效果如下:
$ z4 j- E8 R, y6 \. M
$ N) ~! V, b' m6 G* D
( e, s: v# w4 ?5 U( D. O% R$ G
8.CSS带有阴影的双边框
( U Y' G' ^; w4 B' ?CSS代码:
5 h$ j( n/ k! `! w, g* l: E( T, m#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;
} 效果如下:
# R2 R0 M9 q ?
, z8 W8 H0 \* v- |% n, n
, g/ D, b: s6 Z" u+ q/ O9 {9.CSS多色边框1 P$ ^2 U( f4 L/ @3 A
CSS代码:4 _0 l J) e% O; Y! z- e, {
#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;
} 效果如下:& C* d" V0 m2 [' K1 {( U& G& H8 @
|