CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。4 W7 {' ^1 j7 H
以下各特效用的HTML代码相同:
; m( C2 E5 s: e8 _/ L$ y3 b8 a) i<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
5 W( D4 t( P' r1. CSS动画边框, [/ B& u; m) ~2 @
CSS代码:
( V! [7 r# J- P$ k" Z3 {% q5 G# M@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;
} 效果如下:3 `2 L& o% `& }& e `
* u$ n& Z! s8 C- Q5 \. r1 ?
: C: a4 M" A9 F7 x' o4 h# i! e+ _
2. CSS图像边框& o0 W2 X2 m O, H' z& ]
CSS代码:7 K, S/ `& `" _" _/ l9 W; a. |
#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;
} 效果如下:
$ V! ^* W7 D5 \2 l
' B7 f3 A* B& p- G9 j7 s
3 |* d9 f/ S; Q
3.CSS蛇式边框2 o* ~' z. \; F& l, d4 f$ K' W9 ~
CSS代码:: C4 Z" V; f1 p' j4 G0 S
#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;
} 效果如下:
; X- j( ^. D7 w6 T/ e/ Y6 t
`* B& C" l% E6 m
7 q/ O$ o/ M' T2 ~. s4.CSS阶梯样式边框! e1 C9 j7 t' R$ |0 S6 w+ }
CSS代码:8 s; h. W! L/ ]; q
#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
} 效果如下:
, L9 t q0 D. P0 J$ u
* T7 t5 p2 r; C. S+ h; L) E& N: \. u9 j4 z
5.CSS只有阴影边框
% p, {, V9 L5 |3 ~ k l3 CCSS代码:& ]) e, T2 @) h. m8 H& f! W6 N
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
, ]0 k- O; X- B) L' f5 D/ J# j
, d2 Q* r; z; l2 N& c+ e3 D7 G5 W
- n& x$ m! y6 Y) A1 p5 i
6.CSS带阴影和轮廓的边框
- ^1 i) O7 V" Q5 L' PCSS代码:- w- V, o( ^8 V, h6 P) }) ~
#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;
} 效果如下:
# ~$ a9 q1 e9 B' {, m$ V
; k1 p4 ^% o R# [# g1 B7 f s
: V4 H) n/ a- G4 i* X& u7.CSS少量阴影和轮廓的边框
9 i( a4 S4 ~" D9 cCSS代码:1 `. m. p& ^! _. r, ?1 K1 v7 c) 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;
} 效果如下:! @+ a) ~. P. z5 }- K7 F
% ]( f2 \3 d! w8 r8 A
) L, h& A6 P; f T5 }& N
8.CSS带有阴影的双边框; @& L) u/ g! }2 G5 E/ \2 p
CSS代码:! q' o6 m, N+ k
#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;
} 效果如下:$ o V: q& P$ J2 |/ i- Q
9 G. y5 J" M" |) Q" _
6 n1 V& e" h3 ~! f4 f& e
9.CSS多色边框
, x1 H# ^. X" u9 y0 uCSS代码:; S. j/ M6 N8 ]1 d" S
#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;
} 效果如下:
_% d' [, i8 F7 y! g8 e
|