CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
3 q% E: x- H. r1 K 以下各特效用的HTML代码相同:7 t5 v2 Q5 V3 P
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
2 v* e: Z9 L$ i7 {2 w. O1. CSS动画边框
1 E. ^3 H s. H5 k c" M% R9 t s, UCSS代码:4 m1 i. g3 k5 e* L& ^' c9 q( F% Y
@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;
} 效果如下:: M; R' }5 @" Q1 }4 L& U' l7 y
' `7 V( e+ o* T( e0 J
' R5 r+ d k6 R1 e2. CSS图像边框2 A' ]3 m2 p9 q0 M6 P
CSS代码:/ J; g6 u& o: G! E$ x8 ]; H
#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;
} 效果如下:
# O- b. b/ V3 E4 f
7 r& d; `* k( {. k0 g+ g5 N, }" F3 o- ^0 f0 _: R1 a1 n: c0 N
3.CSS蛇式边框
3 h. y- D% n: MCSS代码:
) {3 H% B& n+ l( Q- s f3 B#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;
} 效果如下:! F5 \# H1 c" v6 O3 O/ R
5 J5 _& |9 A+ c9 Y
( Z; C8 A- f& ^+ ?2 n2 w/ C7 K
4.CSS阶梯样式边框
. p4 k) O2 _4 H6 b5 HCSS代码:+ M1 O/ N3 J1 t1 } s
#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
} 效果如下:, x6 P3 y5 w4 z! W
/ n$ g5 j) a8 r- v4 S2 b% D" e4 O+ \! J Y { N2 z' L# r6 \
5.CSS只有阴影边框
- C& {- @* X( y2 OCSS代码:
( m9 v9 {" y9 X4 Z, w% S#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:. U J+ E. U# |* Z
" n) I4 ?: F- j& ^7 L d8 o
6 @0 B6 ~, D/ z; c! D- O0 E5 ~
6.CSS带阴影和轮廓的边框
! D i0 E. ]6 Z MCSS代码:- X8 F) ~5 b9 U8 M, C/ N8 `
#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 M8 H4 v- j- m/ _2 I* k! m7 l
( x+ ?) U% a# G& l5 c7 D- e1 j* L% i) }+ \9 S2 Y/ [% I6 ^, L
7.CSS少量阴影和轮廓的边框
* b0 Y8 b& S7 `% h: _5 VCSS代码:9 E' i0 r$ g; o
#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;
} 效果如下:
5 e$ @$ J1 \ W4 P+ _5 D9 _
! [' A6 x7 X% I" T% @
$ G& p& h5 z0 ]* m9 O% S7 Z
8.CSS带有阴影的双边框
) N2 S' u% i# ?CSS代码:
7 B7 \* N: K4 s( o#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 t7 ` {$ w$ m* J3 b
' A: e0 |. I+ N8 Q8 i# K$ K# ~
$ ?& b# x K+ W& |9.CSS多色边框
0 K6 Z" s e+ P3 NCSS代码:; p* i' R& E1 F/ C h( z
#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;
} 效果如下:% s5 J5 e" }# k
|