CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。! ]2 u1 b) q8 R5 t8 a: z
以下各特效用的HTML代码相同:
, n1 E+ p" M" e0 Z<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 9 c1 {4 P& h5 M2 l, n/ Y! _
1. CSS动画边框% H; n+ ~2 t- Q* f7 A3 U
CSS代码:
) s' ]# D, m2 B( J5 u5 g@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;
} 效果如下:
' Z& A: Y l2 n8 V
& b, v2 [$ J" j5 b( W5 ?
* ^: K0 A' e% y/ S* ?% e! k2. CSS图像边框 n1 ]" C4 A- ^1 W; n H
CSS代码:, w$ F# V1 m" c' U7 \
#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;
} 效果如下:
/ ^ W8 b: H! f* w: ?# A6 @) w2 j
/ b3 C1 R9 Y \: S* Y- D4 r
6 \" O: C" T9 i$ H+ t v _3.CSS蛇式边框
& c7 j) K6 ^( H, p/ R* [CSS代码:0 @0 a) o* K( i( a/ T' D
#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;
} 效果如下:
: m9 X) _. s7 o4 h4 d! w# g
' m; P, ^9 S0 f J
5 T, b4 `7 t# k2 _4.CSS阶梯样式边框% Q: v( L! g$ g& q' Y' u
CSS代码:
) z; v/ h# @4 N; n# R' 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
} 效果如下:7 [3 k& C( Y3 A( ^& C. g4 w
; h- A& S% ~$ l: `. f" X2 R0 R7 f/ i" }
5.CSS只有阴影边框4 c: r% U& L3 j7 x; S
CSS代码:2 j' q0 V2 E6 w
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
, t6 J' g0 j9 e
j/ W O+ e; S! ]5 O
/ V& b/ r" c5 V- c$ `6.CSS带阴影和轮廓的边框
. z- Z& D. q" ^' v% K0 [' b( ZCSS代码:
6 G* m6 S6 ^, 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;
} 效果如下:
$ |3 k% F- {7 a; Y
& I/ j2 M' G; r
$ U+ E0 X- Q2 i6 R, o5 m7.CSS少量阴影和轮廓的边框
+ _0 O8 r: X, t# L) RCSS代码:
" B( F( ^- L' _1 m s3 i2 x#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;
} 效果如下:9 n- l: w$ Y' P& g s
, }1 l) [1 x, b! ^* J9 a+ l, u
) Z5 s' K; y: \" {# |* \9 S, Q8.CSS带有阴影的双边框
9 |, ~8 t4 D% R2 s8 GCSS代码:
# b* \* F" x* {2 ~#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;
} 效果如下:
. p6 w7 n3 b& r5 U
% ~3 P% p9 q7 m; {. A7 {8 c
7 X6 W0 B4 Q) K0 Z$ D9 L( |
9.CSS多色边框
) s4 N: J9 ^* L8 zCSS代码:
/ U8 l' @, k) y: H% e#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;
} 效果如下:# P+ n: a& c: g3 k
|