CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
! n4 b/ n! D* F4 q( \ 以下各特效用的HTML代码相同:
/ w7 b; U3 t3 x1 L- b. n<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
3 E4 \. T x9 g6 j$ P, X1. CSS动画边框' W0 R* @2 J6 L! e( S& b
CSS代码:9 a- y. G- n; L6 S+ l L8 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;
} 效果如下:& f/ q' }3 G& O
) H% K' ~% A( c: p+ I
. }8 O% ?4 r( R8 T) [* z: V
2. CSS图像边框
, C/ A; Y: c3 J7 X. ?* UCSS代码:) r' G# H( l; A; a% U
#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;
} 效果如下:
/ w$ a3 F1 t% m- J' E
! K( |& ? h2 `, Z1 E( R
. W- O& F8 e \; w3.CSS蛇式边框3 ]0 V, T4 g0 u/ X) h
CSS代码:
& {7 X/ n! d4 c1 K! V* n, p#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;
} 效果如下:
* {8 q/ `$ G/ w. B k5 W
5 F, ?& y0 e/ X# D* j$ m
6 B# x% \, p( o/ Q2 B; p) |9 s4.CSS阶梯样式边框
4 B& I1 U" \. {/ }; R$ ^CSS代码:1 T. P. K% v% H1 A4 b
#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
} 效果如下: l' J Z+ I; K. ^3 [+ _
7 C/ T. B' s4 c% H" ]9 v# D7 I
5 c2 j* G& B% y- Y% V4 J( _
5.CSS只有阴影边框
* F# P8 P& W7 e+ xCSS代码:& c- X' D7 U6 V! I9 T5 q
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
- R% V4 w0 o6 E$ Y; s6 U& e
4 {, G5 m7 s ]1 U1 M1 }5 U
' r% l- @1 E0 ~% Q4 o- C6.CSS带阴影和轮廓的边框1 d; `- d1 |: z8 i4 |: v
CSS代码:
1 R a3 }) M; {8 d9 J: q9 f, r#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;
} 效果如下:& x, Q* ^; ~, [' }% g6 Q1 ]
( h5 \$ R& \3 U4 _8 w/ A% d H
) A+ B% R& d9 \7.CSS少量阴影和轮廓的边框# z9 \" E, ^6 s- C1 [, i
CSS代码:- O( _& x2 X" M. u
#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;
} 效果如下:
" ^/ F N# _: n
4 _, r% q, l" f3 E6 _' b. N
* Y) H3 a" B* h( b( d% |1 Y3 [8.CSS带有阴影的双边框
9 [3 {0 O" i6 `# VCSS代码:
* G. r0 o$ y/ k3 k% y# ?4 B$ g; R# b#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;
} 效果如下:
( c; p" `2 `# D
' H' y4 y$ m9 P7 P1 P, @9 Z
+ S5 I& x- C7 O# @6 C9 u- F
9.CSS多色边框7 |! y$ K+ [/ y5 P) Y
CSS代码:
( D0 q t4 |7 v+ i# W#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;
} 效果如下:
4 o' {$ F, V3 }/ U5 N( p
|