CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
% B! W: U0 C) p# o3 n) l 以下各特效用的HTML代码相同:. \, Y; G6 w- u: L) s. ]9 b( X
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
5 Q; h! J5 z2 u; |: A( x$ R5 A+ G1. CSS动画边框9 f y* N2 k9 F5 k% K
CSS代码:
1 f, q/ e& N- ~, {@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;
} 效果如下:' L5 i d' W) S5 `8 _" U# T
1 U- g0 f6 ]% \1 h( p& K/ T
' f y: |1 F% c2 O) `0 U0 [2. CSS图像边框0 D+ R; _4 k" Q
CSS代码:
8 i! F0 ^2 v1 V/ M( W#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;
} 效果如下:& Z; g. E V% ?, A, N- E
8 g3 j; W! c2 |6 l( W1 k) l* `8 v
# B) b' h' [$ d2 J5 x. w
3.CSS蛇式边框
# K" U9 ?* c9 e2 LCSS代码:
/ x6 F, t0 {% c& M* _- C4 B#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;
} 效果如下:
+ j; @( @( b* L
$ Y+ G' G/ V6 j* |" J* ]4 r) M- E: ] C% J- q1 \- d( M0 I3 P
4.CSS阶梯样式边框, ?1 J; N$ {) B4 e1 A8 ?
CSS代码:/ `4 T1 }$ }( j
#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
} 效果如下:7 @$ P( B% q8 t; i! r
% ], G' {0 ]1 M9 N# w+ X
7 e1 t, A9 c L8 f5.CSS只有阴影边框
- ^! U7 t' T0 R- L W3 aCSS代码:
4 q( p9 A3 j" k% a#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:( ]6 z# x+ y' f: j
; t: C. m0 v1 \" } m0 Q8 n4 z, e7 ^, G. |( }
6.CSS带阴影和轮廓的边框8 t, e2 \3 G( v: D9 [- V) r% O
CSS代码:
# |( _* L( ?8 h3 G#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;
} 效果如下:, {/ f* b7 w# G; `; [4 l
0 Z+ y( t, y& O6 s2 A! t6 d. x; R: u% w! n* ]8 \ Y( Y# W$ o
7.CSS少量阴影和轮廓的边框/ s2 n' R1 C/ H0 Q1 F) k) R5 F# `
CSS代码:/ \+ T# c8 \( l# Y- d$ s- n0 w/ g
#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;
} 效果如下:
( Z6 F6 `* H6 w: z8 {5 G
+ l, R4 b# O q7 n
7 V4 S* p4 i+ F2 } |6 n8.CSS带有阴影的双边框
$ _8 {+ o/ _2 e' w; M- J6 l* ^CSS代码:( S+ ?+ |- C2 m/ n; R/ W
#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;
} 效果如下:
, T& d' ~+ z* @9 J! s
" `3 y6 j8 c# J) N. e) `% a. y T1 }5 ^$ |; o# U' A% _( ]
9.CSS多色边框
2 Q3 Z& H o2 P7 P3 uCSS代码:
1 }. J. t" C3 g#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;
} 效果如下:/ Z% z" Y/ `% s+ x4 c
|