CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。2 z; C9 S3 @7 e
以下各特效用的HTML代码相同:& \& C( [: j6 ?
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
# ?) K! d1 n, O- }1. CSS动画边框1 p4 X- \; e. R% N
CSS代码:
8 D8 Z. r5 O$ k5 p# ]% e@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;
} 效果如下:! S3 D2 E) @* f: S% N$ S- z0 R
! S; A3 @4 S) w0 c$ p
. n: s0 l" i7 @ a
2. CSS图像边框
% s% r' d- @3 G( vCSS代码:
B x [% x6 z: ]8 G* H: Y#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;
} 效果如下:6 s. t- w K# t5 W
. h4 n% Q8 b3 u; i1 n8 b
, ?1 w$ |$ T+ P7 i9 w/ U
3.CSS蛇式边框4 i e. c& }% d- P+ ]0 v
CSS代码:
# j2 F# l) d/ ^; h, R7 b#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;
} 效果如下:
6 O+ G/ P% u' f- [3 Y
. u2 b% ~$ n/ t' H3 m
V. t$ S; V4 L3 I3 \6 j4.CSS阶梯样式边框* `4 p9 c; M' `- t [: U
CSS代码:
! ~/ m4 u% N9 U0 T#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
} 效果如下: ]' M; h5 J8 l; o
" e0 N. u1 r2 [5 V
8 {1 M( M# e* E9 N9 O5 B0 q
5.CSS只有阴影边框$ j, |1 r/ _% m* Y6 V' g: g
CSS代码:
( z3 A# L- K- c# Z5 Y4 ?/ Q% X#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
* [4 g$ W) Q x! v; ^
- {& r5 m# b5 `' k" C9 m9 u
! ?( V6 T8 Z2 A4 T8 \7 b) D$ y6.CSS带阴影和轮廓的边框( e3 p: K/ L/ B1 h
CSS代码:
: U" g3 }7 N3 c$ m8 x$ h% _$ e5 L/ 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;
} 效果如下:8 _# S+ v' f: @; t V9 X
t; J4 @' V1 _1 {" ]6 c
5 o! B" z) e, x9 f- z/ N9 z7.CSS少量阴影和轮廓的边框' E: h: e8 c3 b- s! h0 m
CSS代码:
4 l( A" n0 F: H! A! v; D" R/ D#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;
} 效果如下:0 ?, T0 R7 Y- Q1 X5 r
+ k0 ]5 X" ~0 M( p) P$ O5 C1 f) q8 M2 E% r- k* C1 Q
8.CSS带有阴影的双边框1 @$ X. L! ]2 p, G
CSS代码:( d9 x) j% G5 b+ P" o' A
#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;
} 效果如下:! i1 U9 T$ I. {- Z2 K% W0 s7 U2 |$ k# p
3 b/ U6 m4 I) f, O# l6 q/ u6 [( n! u- L) m, x ~+ h* m
9.CSS多色边框
' Y% t( N3 k0 A# u& xCSS代码:
v- X+ M O' @3 s! c0 \#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;
} 效果如下:) _! e* M9 n8 S3 _1 g# `
|