CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。. l1 N2 W; m. D& s
以下各特效用的HTML代码相同:
3 c( o2 D/ B9 L<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> ; q% ^* m! [& Y- ?6 z& E8 K5 f. A' B
1. CSS动画边框+ D; m% T& X. R E0 u5 t
CSS代码:
, d0 U4 ]* N( L: 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;
} 效果如下:
% K: g+ g. t- y! q! l3 a h4 Z
6 s# c" A+ m V. Q) N3 ~
. ?# S. R6 C- J2 y* \. g5 t# j
2. CSS图像边框
7 d4 f2 f: Q. x# O4 E5 }CSS代码:
8 V" N# z5 z4 @3 x' z( E; 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;
} 效果如下:
~8 v c$ F9 N' N
1 a3 g0 j8 z: f0 v' t1 Q( V P! a; R# ]" t
3.CSS蛇式边框4 J3 l2 y, U! U2 j* I, k
CSS代码:# q9 M: L$ J+ n/ Z! ^& x2 f) L
#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 X9 x0 O& H, i0 Y! h7 v4 h
* u6 y) D0 N9 k" G# |% Y9 J: {
9 K8 X+ M. d' m
4.CSS阶梯样式边框# ]1 }# p& ~' G- Z) s* w+ |& e4 A: A
CSS代码:4 {1 Q5 z. C4 N" 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
} 效果如下:
8 V3 y4 u r; y
- A8 D: J0 v9 T9 i$ n% e! E0 g) a! j( o3 D( ^
5.CSS只有阴影边框$ e" S9 C; ?+ U/ G1 Y
CSS代码:
6 U; P( w1 v* C3 g7 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;
} 效果如下:& A' v6 y, W3 o8 g
. N" Q4 p/ |) }4 i1 Q
( }) C5 E( s, \# ~6.CSS带阴影和轮廓的边框' a9 y3 n3 M& J; b, B; O
CSS代码:0 V$ i8 h) ~1 Z) }! b
#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;
} 效果如下:
5 o. d7 e# @2 s! }, M4 k g0 c
; Z, [1 ?& n* g4 w3 @
+ v ^" n$ K" e7.CSS少量阴影和轮廓的边框
, o1 ]1 ]- J9 T( J9 eCSS代码:: p5 x9 g/ F+ K W
#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;
} 效果如下:
8 C! b4 q8 _! q9 \# U
1 D: [1 j M9 H) b
$ k' H- J& W0 m% S
8.CSS带有阴影的双边框9 s( \, ~- v$ S# X% x$ P/ g
CSS代码:
3 ~0 d7 ]+ n" D' R#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;
} 效果如下:: U2 ?) h1 v m7 D) E0 m5 j }- ^
2 X9 j/ F, {! [0 q7 z/ {+ f7 B& d
% W A& K% s3 \ v2 j l9 _9.CSS多色边框
+ T6 _4 j: \$ C) BCSS代码:4 T9 R6 i8 F" ?$ ^$ A
#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;
} 效果如下:
* r' m A4 i' A5 l! D* @ r
|