CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
7 t& J: C! H. Q% N+ ?0 \ 以下各特效用的HTML代码相同:' ~- e8 a+ `3 d
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
- T1 X9 ~3 }6 d* s O2 v0 y; Z4 h1. CSS动画边框
- J8 r! Z& w' A( d3 xCSS代码:
6 l) M& @/ f3 W* A@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;
} 效果如下:
* ^; ~# e. {3 v+ ^
, }: F: H% `8 N, i8 o0 \0 r; ?7 X* i2 Q/ N! q+ S
2. CSS图像边框
# Y# s+ w5 x7 e# } B/ ACSS代码:
8 x% f% w0 E$ n( M#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;
} 效果如下:
( a2 f+ j9 Q$ H; E. O
4 G/ f- o, D) F* K& L) F/ P7 k: b
# V4 J+ q/ b$ d% {6 M) f3.CSS蛇式边框
( t0 G0 m3 Z5 q; OCSS代码:
2 x8 s$ ~% E, P' S3 \#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 m3 z t7 S3 z1 h; r; o
3 E# X. {8 U n# z1 B* X6 H' a, r$ A+ H" j; q- a+ k- ?, U
4.CSS阶梯样式边框
% k! S2 E0 P! T2 _( NCSS代码:
' D& r" H% {$ N1 p3 D#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
} 效果如下:
+ ]+ @/ W3 w: |3 \* S9 M* M
; O0 z# Z; M! X
% D+ _5 q% d" `7 x5.CSS只有阴影边框
# _$ M4 v0 I9 B `- I4 \CSS代码:# r* G# h. Q7 e% B! J @0 A2 f$ 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;
} 效果如下:" M* H d* N& ]3 E% A1 ?! X
( `, ?) z2 S5 e- b9 A1 c1 \/ B0 x, [
9 t5 ^2 l& A7 e1 O& M6.CSS带阴影和轮廓的边框2 U; n: n2 k+ r3 b% N" ~
CSS代码:# {1 e8 I, P# `8 r& J
#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;
} 效果如下:
9 J, s; l- u* a) h2 N
8 {$ U) |. K% P8 D! _( d7 D$ y% p* j' N3 S3 u: ?/ a; u% ?
7.CSS少量阴影和轮廓的边框
1 Y1 E% p6 a1 m4 U3 [7 tCSS代码:
, m' @6 z; o' t- H#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;
} 效果如下:
( I& J% R+ d+ J
2 ]6 V2 |, k* M7 Z6 y* M. }* l$ C: N Y9 b
8.CSS带有阴影的双边框
2 M: [4 Y+ L4 i p2 q- [/ d0 _CSS代码:6 L3 D" ~6 }- v+ K+ [
#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;
} 效果如下:
; c# t, h5 X- h, W
( z0 L0 k% K/ L
- `) d+ T& M& Z+ p# U! [9.CSS多色边框
' E# }; b( A0 P) QCSS代码:
! f" r5 a& f$ t# o( Y- c8 M0 n$ b* r#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;
} 效果如下:* L* d7 `! y! F; h
|