CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。, u( t4 g: [5 i- e& n
以下各特效用的HTML代码相同:
' @ a/ w0 B9 I<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 9 X" H$ _ j1 E
1. CSS动画边框
; \: A6 J4 T" P) i" y0 [2 G* n- \CSS代码:
" N5 n4 K" f4 i( ^@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;
} 效果如下:9 ], ~, @8 k: b, H& y# n
9 J- p1 _" b% V9 z* p ^( i) [9 B4 |. q9 k5 Z- T+ K
2. CSS图像边框
! L: T x. f8 I O2 O: xCSS代码:3 |0 n" K4 F0 f
#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;
} 效果如下:" P0 n* i9 _6 ]+ B1 d" t
- K3 N3 s6 x2 y# H) z! C2 I7 p2 W& I9 R. W; t, j2 T, }1 }) m8 }8 y# M8 o
3.CSS蛇式边框
& o% S: G% E9 R7 Y5 i! }" CCSS代码:5 z% n8 f0 I' x! v# W1 Z% m- D" c- _
#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;
} 效果如下:
, n/ F5 M* B# q8 Q/ K* h a
$ x& ?- B. x( s, P' d
/ V: {$ m! H+ X1 P. K" i4.CSS阶梯样式边框' Z- t) y8 H K4 M( W. `0 k( b
CSS代码:# ?( Q: E F0 l! V* O
#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
} 效果如下:
+ f3 r* Y8 r6 |' o: \1 M, \
+ I9 M% h2 X1 A$ }# l5 d, {
+ ?5 n* Q& O& o5.CSS只有阴影边框6 U# r- L9 R" a, E0 ]7 j
CSS代码:
4 V' w6 }4 C8 T# q1 }2 ]#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
7 \0 c% _: G9 Z5 ?8 b D5 x
2 y C- G/ s& Y0 Z2 B6 I0 |0 q$ T" |, N" i9 P+ c5 O
6.CSS带阴影和轮廓的边框
! ^1 r: t0 w/ r6 i% bCSS代码:" j4 }" Z7 i6 h" ^, L
#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;
} 效果如下:
) b2 F- K# i4 K+ w
( e/ P* H- \( ~( x( q; ?" }5 y7 K( K7 h
7.CSS少量阴影和轮廓的边框5 V8 W' e+ M9 N3 I
CSS代码:! f+ d3 }* Z6 }2 Q
#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;
} 效果如下:
" N! T: C* r% _9 q
! s4 d, v) z+ y7 ^& a [/ \0 ?
4 z c$ r* |% \& p$ G% ]% _
8.CSS带有阴影的双边框
- d# I! \' H. m: R0 u3 tCSS代码:0 i; Y" W) d. I% \- Z- a, Q
#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;
} 效果如下:8 L. G( Z; D0 R/ J6 b/ ?
' D+ Z/ r# Q' E2 c: r5 w. w8 o/ i
: F1 } `% u5 e7 \
9.CSS多色边框" C2 [) X2 |3 W/ J7 w3 \
CSS代码:6 L7 j6 y( r+ X' k: f; F" i" e) 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;
} 效果如下:# b: U" F/ E! X9 t& K* h A
|