CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。7 f# t9 Q* T! J2 i) n& _6 h
以下各特效用的HTML代码相同:
& ?- K2 a3 Y; D# |0 y+ f3 x<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> + `2 p) P5 h4 U# w
1. CSS动画边框
0 @* u7 j8 t5 d ^3 wCSS代码:2 S1 e9 K9 M7 `* s5 f
@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- W* T9 j- k, }
3 T# k; g; N5 Y$ `7 z0 b) A* l$ q; [% ^& S" N0 K5 o, P
2. CSS图像边框
7 J: F4 I0 E# H# ]CSS代码:" B1 V$ t2 e4 O; F) Q- A* 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;
} 效果如下:3 l- `/ O! B9 f3 l( J; O- v
2 ]. m' s, d7 `; R" P& m3 W
9 Z& R- q& ^2 i3.CSS蛇式边框% r' t+ X. P ?! ]* l
CSS代码:
+ t; l0 b4 W5 k#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;
} 效果如下:4 ^5 Q; C I& ?# ~, b
; h' G. _" r$ |5 Z, R
$ X$ Q! R/ g- k' P" j7 t) c. U4.CSS阶梯样式边框
r0 Q' D% D7 e( E0 }, D/ cCSS代码:+ _2 x) l% x2 W- q# I: h
#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
} 效果如下:* p: i2 Z- R3 k9 N0 \+ @& Q
/ q" K9 X, e$ v' Q( O9 D
3 }$ F/ [4 d7 h/ ~! m/ M5.CSS只有阴影边框
; x S3 |! K# A0 Z z7 {6 {CSS代码:
- r' O: p W) ]' v8 k$ I. ]#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
$ Q' I: h6 i! H' J0 v& \% s: Y" h
0 x& f$ x+ i+ } D% L+ c! d" o1 w6 z! d8 p' N) P, K
6.CSS带阴影和轮廓的边框& a% Q$ x) @3 I$ Q
CSS代码:5 i7 T/ i; f) `
#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;
} 效果如下:: R* S8 c' w& r' j# z
5 J% }# ~) \* E/ Y( ?! ^4 y" U# b
6 C" h; J E- T }: U8 I0 s7.CSS少量阴影和轮廓的边框6 n. o& w* j( A$ [% v$ B
CSS代码:
! |& w* {: x1 ~7 _! Q#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;
} 效果如下:
+ ]! ?. D3 _; |) ?" L" B7 e
& U p9 k4 m0 u1 V3 Z
3 s: F& I$ M$ T8.CSS带有阴影的双边框
8 u( l4 w% m) f1 r, k rCSS代码:# M, O. s9 C: D+ ~( C/ Q6 e$ }1 _
#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. q+ A c4 D2 f% |, F" B3 E
4 w% C* L( i$ T* Y' x
+ M. ?3 p9 b; Q0 }4 }5 F1 ] A
9.CSS多色边框& Y* v/ J" j o
CSS代码:
4 h3 u/ r* D7 f& I1 c0 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;
} 效果如下:: e2 k0 T- D# X* r' Q
|