CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
7 M3 b+ H, S9 c: e 以下各特效用的HTML代码相同:
5 [4 E" B8 t% h9 q: k8 L<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> ' S+ q3 T3 J- x0 h! v; b# K3 M: x. K
1. CSS动画边框
0 j# n/ F3 I" x: O. U' zCSS代码:% D2 N, o% Q: z8 g% U& [
@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;
} 效果如下:
% R" G# h. o0 y' n: {& W J2 E3 m O
6 ^' o* x" z5 h
, R3 w9 ]- G/ L b% e& d, e l2. CSS图像边框% i3 i- p2 Y; S* U
CSS代码:5 F6 ]" q; B& J+ G
#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;
} 效果如下:
! N4 V6 l5 t$ q& |$ x' S* p0 b! n
, r. ` f, ?* z5 Y& H
4 J- Y4 G+ K0 }4 s, w3 W% W3.CSS蛇式边框
% `" b+ t/ V7 ~* q" ]" g- V) WCSS代码:! l4 s7 w& b, S1 Y/ s" I
#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;
} 效果如下:* t4 T+ ?$ Y$ ]0 L/ I4 n9 ]
# I# L" ?- S6 k% s, |- ^ x( d1 V
4.CSS阶梯样式边框* c p* g2 H8 K* L* [
CSS代码:/ A# Y& a. P8 d+ 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
} 效果如下:
1 p' n* Q/ r4 `3 D( }9 D. h7 g& g
9 z9 N9 h9 }: j8 b' g
, ^) o# `( F* V6 K5.CSS只有阴影边框( c1 i& o: }! A1 v
CSS代码:" P5 H, p# c. @% J# M* d
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
' [* m+ Y1 c2 ~: N- K$ k0 W
8 h+ V/ K/ x- K; C: A5 g+ z+ j
, h; l" g4 Q4 V: \6.CSS带阴影和轮廓的边框
+ `; u8 O* f1 |! t3 X7 iCSS代码:
`. f! P+ |) U/ P" 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;
} 效果如下:2 H( N; h" q2 i# ?
) V w) H- B% G% D
& O1 }% u! N' F. ]( _8 I# d7.CSS少量阴影和轮廓的边框. u! \. x% p+ H) {# o' x
CSS代码:
! {3 K# i( @3 e& z# J/ { e#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;
} 效果如下:
# r: L" ]; v3 ~) F
& {, a' g9 Y9 v6 c5 Z3 {% _- X7 y R2 O8 y. {# H- m
8.CSS带有阴影的双边框
% j4 J, x6 y0 uCSS代码:# D2 i( Z# x, O1 y. l* S+ t, ?
#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;
} 效果如下:# s2 {6 \2 h! @- o- r
! `" _/ |$ Q2 F6 |0 m# ~2 P: I! u M m) ^: I4 X
9.CSS多色边框' C' B/ d2 n: ~) h2 j1 E2 i7 O+ C* C
CSS代码:( z7 U1 D5 N* L( g. s4 l# t
#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- ?3 z/ H. U" K# d
|