CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。, Y' X9 M, _" v, g: Y P% m8 i% u
以下各特效用的HTML代码相同:* d/ ]3 T1 }4 q/ p
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> / A9 i1 J3 c( }/ V y7 i3 c
1. CSS动画边框- h. c3 j. W' M k: G
CSS代码:$ q- u! B' k$ E' {" A2 @: K7 a
@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 ?* g. J9 b0 [6 n) p: f0 ~; `
" X- ^ x$ G' ~8 |4 j2 |. V6 t9 ]3 x# v. m3 g- u9 x7 y3 z
2. CSS图像边框
# [6 j3 d6 c2 GCSS代码:, \# k+ n& Q2 ]; S0 X- _+ 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;
} 效果如下:
3 r% f0 f" o9 ~" `6 E3 h
% L) Y6 h8 W6 N" M% B( b9 Q
% W8 ?* x" k/ f$ m' p/ Q3.CSS蛇式边框/ p9 C- k: {# ~
CSS代码:
/ W6 W6 `. e6 ]2 W$ P% x# z! `* E#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;
} 效果如下:: ~, x3 t( s, F6 Z% q- X' U
- ?+ b9 s" N; z2 z2 `
" b) }. m" ~: O# v* Y8 L4 u Z, e. E. Y4.CSS阶梯样式边框
$ I% _" C( t3 d; |2 MCSS代码:4 ? d4 j1 I9 \( s7 g) d
#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
} 效果如下:
/ P% x+ H3 T3 n! @' E# f
/ r7 B! a9 f' N! B. w+ F/ u
f& {' f9 s1 S5.CSS只有阴影边框
7 Z3 i3 Y: s3 _& w' s( h, xCSS代码:/ w& r" e6 ~- t6 u5 _( v
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:3 C/ S- f. [" b
0 P+ W) N7 c& Q7 `5 X+ O0 N8 _) K q
6.CSS带阴影和轮廓的边框
9 l8 ^) g6 @* T mCSS代码:% h* \8 J6 K2 S" Y# x
#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;
} 效果如下:) [0 Z2 u- W u1 Y5 q$ f
: s+ w _$ P6 I; D+ `6 l9 S
. c9 w+ `9 K( w% v7.CSS少量阴影和轮廓的边框
$ y% o {5 N3 a; B) kCSS代码:
* f0 m& g3 t1 [+ K& ~#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 l6 n' Z' k& M& q
0 a, Y- O" c p! p! b: Q
. g0 h e) x0 j+ Y u S
8.CSS带有阴影的双边框
8 [( N$ k0 N& \0 UCSS代码:
) B! \0 d0 N' S) q$ y$ J#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;
} 效果如下:
, r, s8 v( f$ f. u1 J) L; G k5 W
+ \6 Z- G( r( }) V; Z! V h9 J# d0 a. [: I
9.CSS多色边框
6 W3 R$ }9 d1 |% o% x# YCSS代码:, E2 b: Y z4 I( H: z* V3 ~
#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;
} 效果如下:" Y1 \4 e$ w" m# h
|