CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
& z, e" {0 J/ [" { 以下各特效用的HTML代码相同:# x- z: s* z9 X% |8 o. k$ c" ~+ y
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
; G0 Y7 ~" C( ^5 G7 b3 w5 m/ ~8 {1. CSS动画边框
2 x! N( x O2 \# ACSS代码:
+ a% V5 F$ L% R& w; p; K@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;
} 效果如下:
/ L9 {! B6 }- Z6 Q4 x. C( r
/ J+ E# _9 W/ n: ?
- e% s* e$ E! x$ D8 ~) Z0 _2. CSS图像边框0 T/ C: s2 e+ ?4 ^2 ]
CSS代码:
3 A3 x/ o& F$ T' Z' n& v' x# H#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;
} 效果如下:$ `6 K" p* C6 F9 ]6 O
+ O2 E; w& H4 `/ {
" B& _, @% q, s% p+ k8 n3.CSS蛇式边框
+ L% ?9 e' Y, d" `: x% |CSS代码:: |. Z6 `0 s% J L( L3 X) q. Y
#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;
} 效果如下:
! ~% l5 Z( P# p* j5 t
# @7 _5 m* v1 Z( ]. h+ h
) t; r/ U- a0 s# j6 p3 p) p4.CSS阶梯样式边框
0 ^$ [7 ]: |( @( E9 |CSS代码:3 _5 ]( |& g! O9 P5 z* 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
} 效果如下:
; \9 R0 _* U- H$ Q8 _
$ z. S9 g s. m* [5 R9 K
- M% I3 R. G3 u0 Q5.CSS只有阴影边框
) W# f4 S1 N' i7 Z( u7 mCSS代码:
" S& ]+ [6 c* c- }" F) a3 i& q#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
7 }" T* X* q' I1 h8 x
: `' G o/ V1 Q4 P; ]# ?9 E
: t: c9 B1 A3 ?. C6.CSS带阴影和轮廓的边框
& B- b% `/ I# Y; KCSS代码:
( t" H) S8 C8 y* ~0 |6 g8 C) R#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;
} 效果如下:
" w" ^! l2 ]7 t- e! x0 h# j) w% D
% P I, k! D: e- m. D
+ R' R4 f! a6 N+ U
7.CSS少量阴影和轮廓的边框
, I" S/ D. L2 KCSS代码:
/ U/ \' |8 q7 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;
} 效果如下:6 C J/ c2 \7 A$ `
1 ?% y1 D R# F6 Q: S' Q+ x, O
; l! G% k8 j, o' d: D9 Y# F8.CSS带有阴影的双边框
% ?4 }# v6 ]/ T6 v! ]) iCSS代码:
7 i$ E' N& p6 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;
} 效果如下:- I- i* X s% i* {, q: D5 m4 w
' C; V; C" S/ r( S
- ]+ A8 g5 p2 C- U9.CSS多色边框
2 a( i. Q9 ^% d( g7 L; wCSS代码:* Y) R" X; O9 T$ t, s, L# a
#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;
} 效果如下:( B4 R5 d! E v r% F: Z
|