CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
4 b+ J- C8 ~# `# u* u- }: ?: m 以下各特效用的HTML代码相同:
0 G% C6 F% ?. G( p9 G3 e# W<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
3 m, \+ ]1 [; [( `5 O1. CSS动画边框) w% I( y0 w" Y, S7 o
CSS代码:
% c/ x2 F0 j; Z8 o0 L' s0 t! J@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;
} 效果如下:
# L) z, a# Z2 ]" j9 D
1 d- Z1 w, x+ O6 e1 s. F; ~0 G; [$ q) ]! G* B6 R
2. CSS图像边框0 A3 _# @" A9 ^+ c0 q3 @
CSS代码:
5 h6 L0 @3 }! F) 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;
} 效果如下: ^8 @+ S; r; y
9 c# P) b' l* W9 f! `, N- I+ e3 }& Y; i
4 b7 _0 }9 X1 o% }/ r3.CSS蛇式边框
; l9 q- O4 i9 [4 |CSS代码:
% [ `2 H4 W1 e4 s% U0 Z" g& g#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;
} 效果如下:
. c, S5 {) @* z8 w
" @1 S" p6 ?! J, L8 t1 z* R/ j M8 r/ t3 }6 q2 {, h: E/ Q$ F: K4 d
4.CSS阶梯样式边框
6 T) K, L5 \$ S1 ~& v, \* Q5 HCSS代码:+ T# ]( \ P( |3 u+ y: G. o$ ?
#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
} 效果如下:. k, N( z, d/ ~; R. p
% i# Z. B: j8 f0 V/ k+ q
, Y5 D, x: |) y5.CSS只有阴影边框
& j+ }' G0 D% x2 y3 u( NCSS代码:
) |0 k' ]# K2 l#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
* K' f4 _$ a) N& J9 ]% ^$ {4 F
! t- }$ D. J4 l5 j x; A/ u! M7 ^+ j
6.CSS带阴影和轮廓的边框( {6 `; ~! ], o; ]- `$ M
CSS代码:" u- B0 z- U, F5 H0 k( t8 E
#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;
} 效果如下:
) e) t% J: D8 {" t! n2 ]* @
, }- D9 k) T# l" s+ I( g
' X, u3 P" T0 t7.CSS少量阴影和轮廓的边框
" Z, n3 u: A3 e0 C& rCSS代码:
3 B+ ]% Y' G+ `7 a1 x#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;
} 效果如下:
" v) a. P0 U6 x6 A
! D! x! A1 q6 i) ]0 K$ E0 p
7 n5 n- y, \. O( N3 M8.CSS带有阴影的双边框
5 K9 q( M: E9 ?: M6 YCSS代码:
& U. ~8 V W! N4 C/ o2 h#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;
} 效果如下:) u! Y, R$ L. _/ ^6 r
: _% x; q8 u. K7 G& H
+ s/ a/ u) d% a) K! T9.CSS多色边框4 W) f& S+ |+ b
CSS代码:& h8 w& t$ H' i. T9 g+ s# y) W% i
#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;
} 效果如下:
6 w6 R- Y; E- w1 _( c
|