CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
# k2 J6 l! B2 q; d0 N. ]4 Y- l) R4 J 以下各特效用的HTML代码相同:
E0 A1 ]" O8 P<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
: ?/ q! Y4 t4 b# r1. CSS动画边框
8 J) p/ N2 W# R) I% |CSS代码:
4 `( w; _/ V/ [! N F9 O: s0 Q6 z4 @@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;
} 效果如下:
0 F+ ]- ~9 w K8 v3 T6 ^6 |/ x6 A4 V
( D( U3 E& K1 R" G- b- f/ S9 t! Q% {' L& e
2. CSS图像边框
9 _# ?2 ^) G8 {1 sCSS代码:
7 I: r2 S; n9 I1 z* |1 w1 {#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;
} 效果如下:) Y0 e1 a) P4 g2 c# ]
: r' s4 X# a! Q8 F9 x+ ` l0 G. r4 l" D$ ^3 q7 |' s) ]6 r
3.CSS蛇式边框! [/ x2 k1 o+ h5 X6 ~
CSS代码:/ |( ?* s% G7 }7 B) B' J7 v4 E o
#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 J; p d1 W+ N/ S' D* ` e
) `1 r, o6 T% d7 {
7 H$ B' ~3 p/ B4.CSS阶梯样式边框5 r# F$ u% E- a& Q9 `' S/ R
CSS代码:
) S3 C$ f8 _6 a0 x/ L#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
} 效果如下:
$ z3 [+ K$ W+ M* [* p. r6 J. L3 }' K* r
# Z8 m9 e/ G& W
( ~4 n7 e$ W j+ H1 h; S- A) }5.CSS只有阴影边框 v2 x4 X; r$ {
CSS代码:1 W) T% b; k4 X/ Z0 Y9 N
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:" J, z* u3 y) `8 P9 m- c" E! x
, `7 ]/ Z4 _' y* ]% c
8 K0 m6 V6 E, o, W& G; R6.CSS带阴影和轮廓的边框7 h4 F/ Z+ C# t8 _6 o
CSS代码:' ]8 }' a" b: ?0 y- h- K: w' G* 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;
} 效果如下:8 U, Z5 h9 l, i3 I
* J+ O7 n2 k6 Q, f ?' q
5 R" f0 j* g1 _5 Z7.CSS少量阴影和轮廓的边框" O, P8 E( S, H1 P2 T! j4 P
CSS代码:0 y8 Z D4 W/ d; v) 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;
} 效果如下:
! A& K1 b( Z5 z+ V
: n8 |/ S0 t# Q; G6 @4 E3 t
. R: D0 t1 s& [) K2 i( l& d
8.CSS带有阴影的双边框
' x5 Y% h i; f4 a2 n/ M) r9 X& aCSS代码:
: d. `4 P7 ?) r; b+ S: K+ s#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;
} 效果如下:
) S+ v+ Q% ]$ ~5 ^
7 k/ i( O( F+ e# \ h& B
3 q4 y3 d! O! {4 x* t& {( l9.CSS多色边框$ W+ i+ B! D$ [( E. }- U* y
CSS代码: J' c) z2 o1 i1 a% |" {! 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;
} 效果如下:2 ^- g# W Z% _ J
|