CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。! P3 Y b. @; M8 c$ n$ `" e
以下各特效用的HTML代码相同:
# w3 d/ B+ s7 M<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> " h) n. X9 C0 {/ |) B9 z' I' q
1. CSS动画边框
# g( E7 \6 V/ H1 ^, l8 c) K1 z. [CSS代码:
; P; G1 K% d# U5 N@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% i2 S) [: K" w" i
! p: M/ u. { M: I1 F; m; a# {
& V0 V" ] I# L( c% A# v) e; H
2. CSS图像边框3 J& E) S) H( k2 a& d4 d
CSS代码:
2 W, d2 F1 t3 U* N( x#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;
} 效果如下:
2 z* o+ n" S$ |
7 v: G8 i/ l, R5 O* k
. B- V l0 v$ {& B) T
3.CSS蛇式边框1 }! O/ k ]# Z5 \. w
CSS代码:
: X* d3 w: A; D( F$ { l#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;
} 效果如下:
; V$ m( b3 y# u+ o
8 ^1 N* [6 L7 d; n7 ^
6 o/ G1 X+ ]" C; C
4.CSS阶梯样式边框, v) f, M9 w# E& y' D* G
CSS代码:
& U) s7 w# D2 t( O#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
} 效果如下:
/ J: e8 B4 V% J4 i& y
% n( Q- g4 \! {; p3 @! w
, f j7 g( H3 j8 y5 x" Z2 u5.CSS只有阴影边框
* N6 Y3 I# r; [% D8 b# _5 R! C0 YCSS代码:
: X1 A9 t6 T8 z8 I1 O2 T! P#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:5 k+ Q9 ] z6 w( G4 M7 K* c ^2 ~* e* c
: w4 w% _! j3 F& L; X1 a& L$ }* f3 |% ]7 E% r# o' e, @4 \
6.CSS带阴影和轮廓的边框( J" U& Q* s) a v; }5 l$ M
CSS代码:$ t. g5 c4 n" R# q, v% s/ S' C3 V7 s
#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;
} 效果如下:! [2 g2 b" h2 p2 V; c% k
2 Z9 ]7 _4 y2 a3 y% \+ E! E
/ F: W4 [8 \1 g w7.CSS少量阴影和轮廓的边框
) V0 X3 M6 I4 R I! L9 b. N" B+ YCSS代码:
* v8 b+ j+ _: {# P& Y#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;
} 效果如下:' r8 s& Z/ y8 ^
, v3 n* Z3 m: q: F0 O, k' f
' v" }% Y$ E1 f( q1 v8.CSS带有阴影的双边框2 K. K1 {% `, i% R
CSS代码:5 U" o& j8 c0 Z8 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;
} 效果如下:
. d9 x8 W' p1 [* J# J! f
) L! M/ y5 L' V1 k
& N. `, u3 S1 y2 e9.CSS多色边框, G, l' B' h6 u
CSS代码:/ [7 \" ~* |" B
#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;
} 效果如下:
K' W9 q9 f: ?! B" y
|