CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。" u7 c# Z1 c, a$ j( S; ]
以下各特效用的HTML代码相同:
1 }1 f1 ~9 j4 ^# n: G<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> / w- N; P' h; z% y ]/ T
1. CSS动画边框5 a& I1 W2 w" b) N
CSS代码:
' B* v* Z8 }; H; }5 z3 v, s: u@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;
} 效果如下:
/ \! i6 H6 ?4 u. o( s: f" R( s
! T6 H" ^% Q9 a- P
' S2 S- V% a" P' D7 e" S2 ?2. CSS图像边框4 h) d( v/ z! S7 P' v# j
CSS代码:
+ I5 g% H& L a G0 N0 s% F: C#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 e2 W% Z5 U+ d! l
' E! U( ^6 f! F0 ^' `& ]
) J2 k5 @7 L! I3 e1 h
3.CSS蛇式边框
/ C. D7 V/ u7 I u& ICSS代码:
4 \+ W0 v7 h; Y5 f5 E#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;
} 效果如下:
o9 t! r, a( H! e# t3 ~8 w( o9 z5 U
/ C }8 M3 {2 e& V; i# O/ ?9 D" P. k+ L( d
4.CSS阶梯样式边框* N1 ^- s6 G1 O3 y% k8 d3 V" H
CSS代码:
4 J2 _& `) Z4 q- c#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
} 效果如下:' D4 r1 N. p8 ~, _ ^
3 l3 w' @8 ~8 s) Z/ R) S
8 w% L# l9 k! Y, B& R4 u- ?
5.CSS只有阴影边框
( t$ P; n' U3 yCSS代码:
P8 P: X M) }#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
$ B! k2 q6 O0 X
) F. g# A- x1 E3 ?
1 x! Y: e$ D5 }0 g& M6.CSS带阴影和轮廓的边框
7 x* a* b* D v& B0 E) Z- `CSS代码:
/ c# O- x! L! S. 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;
} 效果如下:
: r5 l6 t8 w' O% m# O
$ S! p' R: z& o
% _8 c7 W a$ @: F* {- t/ Q. N# r7.CSS少量阴影和轮廓的边框
" }" ]1 f4 U! j1 xCSS代码:3 ?2 P7 v8 t8 {# 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;
} 效果如下:
. Y" }# |1 L/ r/ T
# F2 [1 ^8 |* r9 L8 X" n
- ~0 o+ H: ?- U/ o% m8.CSS带有阴影的双边框! J3 \0 l9 m1 C' o k$ ?
CSS代码:* \& r! T# s/ x. M, c S+ {
#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;
} 效果如下:
7 i- u" }" ^) x; u* T: V
4 Q K9 g- W5 I3 B
: M1 }6 r2 |( L9.CSS多色边框
3 Y! o0 h7 {5 BCSS代码:! [. p: [7 R1 i* v- r. H
#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;
} 效果如下:% m3 u9 ]0 Z1 n5 `4 ?
|