CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。0 t1 { \# O- s$ M, T7 e, H2 ]
以下各特效用的HTML代码相同:5 Y, [5 w% `' \) O9 S
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> , o+ x" y5 |+ L' L# \
1. CSS动画边框/ i4 H4 v* q0 y; }/ T$ x
CSS代码:$ Z# N1 | k7 {; y$ z Q
@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;
} 效果如下:
) Q! e4 k( Y$ `, t: B
% ~0 C. H7 ?% |2 I; G Q& }0 s% @$ q: `% S
2. CSS图像边框4 Z$ X ], G3 l$ p' `0 @& ?8 O: g
CSS代码:$ L! ]( B* J; F- c6 Z
#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;
} 效果如下:
, M- A( l, R9 m) W+ A: w
N" I& w$ [# {( l
( d, L1 p3 j5 x; q( @8 o. j# s3.CSS蛇式边框
# f7 f" \# K6 h+ d) `* zCSS代码:
, G% O; R0 _3 D" {. L) h#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;
} 效果如下:
9 o. W1 |' D$ U' F. U4 _
# |, U, Y9 e* l3 q9 I2 p. z
2 B/ f- m1 h( L' ]4.CSS阶梯样式边框
% L/ v5 W V( O" ~CSS代码:
* l( X# q! m" O) K8 Y#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
} 效果如下:
0 q, u1 ~ p" i% a+ `& ]
6 l3 Z- \7 F+ D7 b: x: v5 I8 M; c8 G; e( Q$ c i6 f
5.CSS只有阴影边框
9 q$ U8 T9 i7 d8 o. J' V" FCSS代码:
6 i( ]/ Z, ~; C9 G. M( O) A; b2 o" b#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
4 Y. Z7 j8 p s' d
. y, M0 I$ p4 K. }2 J
8 X5 H! z& U! W3 G0 s8 P* J( T6.CSS带阴影和轮廓的边框
0 q2 I4 B1 X- n' vCSS代码:0 x, o9 `' Q' j. T
#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;
} 效果如下:
* f' E7 G( ?* h7 A. v2 u" g! W3 F
1 z! }3 O' B. C+ r
) o3 t" @) O" q) s/ h( D( f( H7 y7.CSS少量阴影和轮廓的边框0 N3 m& F: D0 x! c) o) Q( o/ M& T
CSS代码:
* B; m: Y) I0 C. `& T& O3 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;
} 效果如下:
0 V$ O( z) y' m7 B" ~
# }% d6 D- Z7 G! [* h! N* l% G+ W5 A! c7 _ H* F5 N; H+ P4 p7 A
8.CSS带有阴影的双边框2 P% o2 w3 @5 N) l+ e$ T. p9 K" u
CSS代码:
( v. s' q5 m2 E, Z7 @2 ]( M7 w#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;
} 效果如下:; U) ~& F- `) P6 g7 {& k% e2 r V
4 ^& M" x V2 R) I
' \) s4 n" {) A" G
9.CSS多色边框6 n! ~+ I0 P0 X- ?+ i# w
CSS代码:
3 k/ l3 e+ ]1 n1 @8 C8 [; G) D#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;
} 效果如下:
$ @1 m. W5 ?% l2 T. I! l
|