CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
! Z @; C6 ^# E7 O 以下各特效用的HTML代码相同:
3 {+ Z* z" N6 f! m. F, z7 P<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
$ @" q1 I3 s+ a% H, S/ d1. CSS动画边框
7 X* T! O% g$ _3 I0 J- c$ f$ QCSS代码:
8 [6 [) _+ P i- p" R6 [@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;
} 效果如下:0 l) i9 N9 q9 I7 U0 }% ~- Z! n
k" W* @9 j6 g5 D; @
5 s2 U$ T/ y. o- [; ]. j2. CSS图像边框9 F4 K: _' G# R. J
CSS代码:* g# L; p$ U' C: Q
#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;
} 效果如下:5 t1 ?! i' u/ ]0 i/ O+ w3 i, R) m
( u0 {$ ?% \3 r: I0 Y: D% Z% x" j5 K/ ~/ O' e. ]5 M: b
3.CSS蛇式边框
) D/ T1 ]0 p' U7 O& o/ OCSS代码:3 O% g) |) {8 A$ R1 |
#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;
} 效果如下:
5 v% B$ Q5 | R6 `6 ^
5 t- h/ ^9 c4 M% u% F" T
, r8 R- Y/ \8 A; W' O# i! Q4.CSS阶梯样式边框
5 X* F: g4 [- @2 X/ r6 oCSS代码:5 @9 I9 J, p" Y5 R. y8 N. A9 g
#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
} 效果如下:4 P; R# _, d$ o4 @$ Q0 }$ a- a
1 o. d% g' p+ Z: b
4 \: @. f) t" s
5.CSS只有阴影边框
& @9 b+ w! E( [& ]* u0 aCSS代码:
2 B, L& T/ u* m#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:2 M# [6 e. [" Y, q& w6 k7 m
5 r0 H, r: l, o4 z6 U/ d" z
- P R+ t* D1 m# E1 T T6.CSS带阴影和轮廓的边框 g8 B% X% d5 L. \
CSS代码:- s0 W' k0 D- S# D 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;
} 效果如下:; p$ T) S# J4 W. y9 P6 e5 {
& {6 h2 U) i S4 H1 _
1 L3 `1 g% W/ u9 Y( E- X% t
7.CSS少量阴影和轮廓的边框4 _- u/ }2 ]) ?7 e/ O% t$ V$ n
CSS代码:
9 v* w; A( u- _+ i/ d$ 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;
} 效果如下:
% S( ]; g' ?7 p" G. U) m1 `
* M! l, s# A+ d# U
( |& p2 @1 ~1 v. @/ D, W8.CSS带有阴影的双边框
) e6 [ P4 s: O/ d* S9 o) WCSS代码:
# [, z- }4 T# @7 a& P$ P#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;
} 效果如下: n0 [2 i3 \3 S$ S9 F+ Z
3 j' k; }" ~6 N# r
1 N! F* X/ Q; W+ j7 k: n+ j9 j% \
9.CSS多色边框
L" K/ D7 r) ?CSS代码:0 m7 L4 n+ v+ S) l" W6 j
#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;
} 效果如下:: q' e( [. T7 T% M# `- @
|