CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
/ g+ c- \4 D' o2 \- R7 l* ]/ ` 以下各特效用的HTML代码相同:
3 V0 n; x5 `) P# z<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> ) S6 P$ {. q3 k5 j/ P6 c( j1 T9 W8 }
1. CSS动画边框3 T9 n$ G) y% \9 P: } @- c( X/ a6 N8 u
CSS代码:; P) g* t) A1 r c3 f" \! G# D
@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;
} 效果如下:
) U7 b! o" t; _" h9 ~0 c. _' F
9 q' X7 ]/ h- P3 y7 i) I |7 y
+ ~' j' ^: z$ @) ]! u. j9 M2. CSS图像边框# f% I$ ?0 @7 i$ k$ S) T1 M
CSS代码:
/ L% ?" c7 z% U( n" J$ E#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" O; Y \/ G8 o7 u
2 J+ Z% I! x$ A; d
$ g3 H. s+ F1 h: D' B5 {3.CSS蛇式边框- @+ X" f* v7 @$ K! ]
CSS代码:
/ C4 ?0 T1 e& ]: \: m- P#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;
} 效果如下:( q; @8 [: H! K+ h% N
7 j& P! B2 G& d) i; u" R- T6 @8 `% X: {2 _$ g5 G1 Z3 U
4.CSS阶梯样式边框; K4 ]3 |; X; P+ b5 f) C* ^
CSS代码:4 ?; X0 N1 ^2 \# u6 C; Y7 s
#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
} 效果如下:
( D3 [: t" t) a% ]! L, o
: h. Z+ J7 m M- ~9 c1 [( ]
: b; y3 \, Y( b6 Q& j3 A( E3 c5 s4 B5.CSS只有阴影边框4 T Y8 X! t9 G! ]+ N5 ^ @; h# c( `
CSS代码:
. H. \3 W6 ~7 }* r, E1 @! A9 B3 {#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:# [+ f0 O% C- W2 X: }* ~2 {7 H
) f6 {$ T# [7 @6 w8 D, B
- Q; b3 r# F2 q% [6.CSS带阴影和轮廓的边框' {& q2 @) H5 d8 B+ E, x
CSS代码:
4 h3 J* d/ g& M$ j" y" p* v#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;
} 效果如下:% H7 |7 l$ M" p
! r4 `! c1 |9 h _. J/ {
8 Z# J% p( X9 \/ e- @7.CSS少量阴影和轮廓的边框
2 n {/ h. O* _" R* eCSS代码:: `$ [# v; K; D4 w' w. _
#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;
} 效果如下:. b0 l- P& E$ S
! T7 L0 a5 Z# q' M g; s
8 Q/ f% X/ M2 K. t0 p- t8.CSS带有阴影的双边框% H; a5 j& Y, a+ l: W7 b
CSS代码:
& V% j B; {5 N; M2 ^: ?1 F#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;
} 效果如下:& G! i/ ?- K2 A7 Z) V
" R& Y& }, q( v3 G: |6 }! y7 d) f6 ^+ l
9.CSS多色边框1 F0 d) m! V" }( `: p( O2 @$ s
CSS代码:
. t/ ?* m0 ^6 b$ \ B8 F. b o; N#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;
} 效果如下:
9 q, [; \) O# O7 R
|