CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
" u3 ~# p& G, e 以下各特效用的HTML代码相同:/ E K; {$ [. P, m) O5 j- i' ?8 }2 O
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 1 V) ]5 o2 F( n! M6 L+ A
1. CSS动画边框
+ b5 f$ C! x" `1 i; q9 xCSS代码:
+ ^5 O ^. D, H' M& T0 X% R@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;
} 效果如下:
: R0 k- K! M+ }5 b5 a: Y
6 V, z& v! y6 j
2 k3 G- \ F; ? W9 ~% g2. CSS图像边框! R: J' k9 @+ o
CSS代码:; m6 I r4 v/ H, o
#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;
} 效果如下:- K! e# N2 Q) o5 b3 F+ g) e
3 l) K$ o0 u* Y9 P/ f3 q
3 V. E0 t; \ \+ x0 D* Q6 v# Q3.CSS蛇式边框$ @) f. K6 ]8 u- T1 \' K6 b5 m9 Z& z9 W
CSS代码:
1 t6 v( C. W* L; ?. o; h( e- ]& F" ?#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;
} 效果如下:4 g% o' w9 ^! r2 `
8 E6 Z7 T" _$ D+ @/ P
4 `4 h5 u+ P& X; R- {) q& c
4.CSS阶梯样式边框+ s5 W7 z2 A; |$ B8 _9 x6 }" J
CSS代码:9 Z% ?$ e% r+ k4 d* H
#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
} 效果如下:! c5 h+ ^1 [& o
! }/ T; ^9 A8 o* m1 C8 x
* s: G v4 t( O# z+ |5.CSS只有阴影边框
8 m6 C+ y# L; K" dCSS代码:
# M- B6 h& r, s! x2 r0 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;
} 效果如下:# {" z% f6 A9 f% j- o/ u& r
& {2 f4 y A& n- G: k
: A& T: B' \3 Q- L7 I3 T$ Z- Q' n6.CSS带阴影和轮廓的边框! q& m' L8 Q+ h$ ?3 H
CSS代码:9 ?* ]4 R* b" J- T% Q3 h4 y
#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;
} 效果如下:
/ X$ x; g2 ^& O3 x" N
& I; W! [6 ]! S5 y/ I
, A; G% |8 G( q" @+ |0 m0 t
7.CSS少量阴影和轮廓的边框
8 K8 E( V' e. U% h: B+ {+ KCSS代码:2 W+ M* {% ?) D) j5 k6 l1 f1 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;
} 效果如下:
9 H, h& z0 Y$ j1 D% Z* T- O7 z5 ?
: J1 m; |/ P3 {& |9 P
8 v1 \; ^) g: I& d2 S5 z
8.CSS带有阴影的双边框! ^. V. h3 m. n) f
CSS代码:
0 B* K( l T" Z( p#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;
} 效果如下:
% m8 N# w7 `3 x# ?: D
" g; v k. R f' z, z2 i$ s" X" s: }$ S: M) _. B: _7 Y$ [
9.CSS多色边框
+ E$ x) Q0 D, H2 eCSS代码:, U' D7 S+ y% @5 B1 {9 u5 E. g# Y
#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;
} 效果如下:
9 M" [+ k: e, L4 z4 ?
|