CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。5 \) V1 A/ i) ?! B
以下各特效用的HTML代码相同:5 O. z( C) ]' E9 T
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 7 O8 p9 c6 |" j8 U! J2 c$ Y
1. CSS动画边框
: W1 K! K+ {* e% S- V4 gCSS代码:7 S* @" X. N$ @% v
@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;
} 效果如下:
+ s' a! s& x, o8 L0 `
* N2 d' M3 B, e" m, y% T
$ c+ N* n" J. d# J7 [: C2. CSS图像边框/ c( A& a& ]* K, f' }; h: ?
CSS代码:
7 P( l* Y. L" S+ \1 z/ f#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;
} 效果如下:* Z3 h, K6 B0 Y( H. q) V# [2 a* v5 C
; {* d0 z `# ~' }* E$ p' _$ N' o2 B, u! r! o
3.CSS蛇式边框
8 o5 H5 s) o a" n \CSS代码:
! A T' k W% o" R3 b6 }#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;
} 效果如下:
+ M, J& E7 Z) p9 u& d& k2 E; y
3 S/ j6 Q" @7 r: D% c
8 e% O! H. `7 v8 R9 ^ S8 r0 Z. R9 L4.CSS阶梯样式边框1 T2 v% W& O' P+ n
CSS代码:* I0 C% i! O6 L4 ]
#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
} 效果如下:
0 \/ f1 T. U+ `; H6 V
' }2 @/ |9 P7 k: q4 r
4 p: r7 o9 N2 X+ j% |5.CSS只有阴影边框
: ]% I% r) P+ eCSS代码:; @/ l0 h# u0 K& ]1 m9 Q- U) I6 y
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:! `: c, m% U3 T0 j( T. s
- V$ |, N9 B5 j! r' {0 H) F! [2 I+ O
4 }; ]. Q3 P. S& R. [) N% }3 k# F
6.CSS带阴影和轮廓的边框: L. ^. D7 [- M3 D2 X
CSS代码:
" V: u/ x; ? [1 i3 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;
} 效果如下:
. [/ V/ z1 `9 D! M8 l# G
7 j$ D W6 ?7 t; C/ M) k8 D' _' D
: O* `5 b6 V# s8 {4 ]7.CSS少量阴影和轮廓的边框# ? D O( L4 M3 a
CSS代码:
0 P( o/ i# o9 D#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;
} 效果如下:# g+ l3 G" M' L. x# z+ M
. L8 ?, F; s6 c/ g2 {9 E; m) S, Z2 Q& [" {" n# l2 T. Q* G, Y
8.CSS带有阴影的双边框
$ r6 {- q5 g5 [5 E2 GCSS代码:
- E. t b6 S' T$ j$ R; o% M#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;
} 效果如下:
5 q' p0 e; L' @- C9 y( W- |- y
# H; [! k' }: A+ v6 o- _( ^
: K7 O8 P5 z8 I! b% y) E( x9.CSS多色边框4 Q3 p! c" b5 @- \# S
CSS代码:- D* ~- [: e4 }' B* y- }
#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;
} 效果如下:
G6 s. B% n5 d3 S) |
|