CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。2 V! N. { u! u+ g( P* Z6 ~
以下各特效用的HTML代码相同:6 b2 L' F& F: [" ]& C$ \2 `
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> : D- q1 Q Z% W2 p; g& b
1. CSS动画边框
% B! w, w& d: f9 CCSS代码:
! H {( p- { t1 N; h@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;
} 效果如下:' K* E: n" r8 `3 D" {7 c+ H* m9 m0 D
5 {3 p2 t5 H; X9 k8 F! _0 Y+ x2 e' g
( d& {! h, v8 C# F
2. CSS图像边框% F7 Q3 c. Z$ ~0 p4 a2 B& }
CSS代码:& P6 D! e& q! L- 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;
} 效果如下:; e B7 R7 E& L8 \. V% X" Q
% Y, T4 u1 h0 N- x6 |- h
v/ K! f2 G1 K" {: Y2 D
3.CSS蛇式边框
8 V6 Q( S7 F) a, b2 D0 QCSS代码:
7 Z7 `# O, w6 X. S7 S$ w9 Y#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* S6 c! M6 p, O% Q
! M% r6 Z- x) c. E8 y# d$ h& s; a6 G& l4 g, Q, n* J& F
4.CSS阶梯样式边框
4 ^9 S* i: E( _' `- o a3 Z. C* KCSS代码:, [& D9 x4 k- r" [5 a
#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 j& O( b) I6 F
' L+ D+ i7 \9 Q0 p+ M" j+ Y9 J
2 Y1 P6 @5 U; j( c5.CSS只有阴影边框
9 I* Q/ |- Q" h8 o" BCSS代码:7 U# O+ x! ]8 ]7 N6 @! R0 |" y1 \8 ^
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
7 c- Q- \9 I( [9 s" R
3 A0 _; `, M5 C* Y/ g1 q1 |: M0 [) R9 }- E" P g. r- n
6.CSS带阴影和轮廓的边框
8 x3 O5 K/ f+ H0 A. JCSS代码:
+ p" @1 v1 X* s& l1 A) Y. {. d1 I#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;
} 效果如下:
1 J2 }) O5 b" ~( Y: e
2 K" p3 C) e( H- E/ L9 ]; n1 A0 K" k {, w6 p, y
7.CSS少量阴影和轮廓的边框# V& p" G, ]- @! X# y; d
CSS代码:
" h. G9 s+ n: i9 p#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;
} 效果如下:
3 z. H4 W1 U3 x3 `7 r0 [
- z2 C- ?, Y2 ]# j
4 n: ^$ G# }4 a8 y) E
8.CSS带有阴影的双边框4 F. g1 V9 g( D# O$ k' ~/ |
CSS代码:5 d7 x3 ]9 p* `- ?# E: l
#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;
} 效果如下:
! r/ t+ a( f% c* z+ A
# l2 E4 u- z( S- |5 S; M3 }
. j6 C) x i/ j: P
9.CSS多色边框3 n* p7 ~3 Z$ ?
CSS代码:4 Z1 o2 o2 s' _* m
#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;
} 效果如下:
" [! s0 d( w% M8 [/ m: U h
|