CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
/ f# g& J& `, R+ @/ k+ y4 j 以下各特效用的HTML代码相同:
% U! K, {/ Y' \; v! G/ x<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
; n; [+ J9 W. D! v! n' I1. CSS动画边框
2 o' u- K. {8 k+ JCSS代码:
& R9 Q d% m8 K( z7 z% b6 i |8 |@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;
} 效果如下:
8 ~- Z) s8 q1 F& z2 o0 _( `
8 N( g, L$ x3 n
! p1 V' ^# C% P# C) l1 h
2. CSS图像边框
2 P6 Y n4 i: L$ R6 cCSS代码:" z/ C1 D+ s7 }4 J$ R" Q; b3 p
#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- k& p# y7 s/ p* ?3 D
+ F9 ~3 ~( u8 S+ Q/ t% G! {! H' W" n
" Y. d) W- Z+ A9 M& V
3.CSS蛇式边框
5 p$ y. C2 ]8 i% c3 K1 ^7 Q6 W. l; s: hCSS代码: X2 {* B' ~1 }/ _/ S9 y) U
#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;
} 效果如下:3 P4 [6 e9 h' p) I/ ?7 v) @
6 H' V+ v2 Y- C* v( L2 B
* t; `8 K1 k2 y2 v9 G+ B
4.CSS阶梯样式边框
) b/ F. {& m, DCSS代码:8 Y' u$ E/ q1 I: y; c
#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
} 效果如下:/ k+ q# D6 \3 `* E: x4 ?' L' }# h
/ Q# i8 }& V- x/ F. U. B7 H4 m- P! L$ ]
5.CSS只有阴影边框3 n6 O; J- q8 S+ J7 g
CSS代码:
6 ~5 A0 L4 K3 d6 M#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:& x+ r- C8 A4 t7 J" O- F; S2 V
$ H. s( `2 {# E0 A' [
9 k$ y% h/ c* y& ^" ?. X6.CSS带阴影和轮廓的边框
6 G$ \0 B; o2 ACSS代码:7 P% \- v# ]% ?3 l" j- z$ V
#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;
} 效果如下:9 G1 s# U& x7 e7 y0 F
( V9 p: [$ e `! w# p5 ?5 V& |
; d2 v5 n$ W! ~7 P
7.CSS少量阴影和轮廓的边框2 ~% Y: G ~2 ]: u3 t- u
CSS代码:& U; `) t/ e/ h
#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;
} 效果如下:1 q- n+ k, k; `# b) l
5 l8 E, s( i# W+ p" ]1 i+ f
4 @4 W& K. c% X4 |
8.CSS带有阴影的双边框% h9 g( k* M; U3 L% w
CSS代码:
# l# {, G. Q M5 f# s( C#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;
} 效果如下:
) f1 R; \2 E- h/ ]2 [8 \9 R
% S2 D4 x3 B0 t/ L; p
6 b/ H7 k0 i% T' p9.CSS多色边框" \" [- j: S( w. ]
CSS代码:: u9 h/ D6 h* S( ?- y, t
#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;
} 效果如下: I7 B% \) s5 A" B# u$ d
|