CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
9 `7 G& d# @$ Y7 m 以下各特效用的HTML代码相同:, L( t; f. F }+ I% K4 t
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
( [- U& f( L5 |* s1. CSS动画边框' d! E& B2 f& o, f
CSS代码:
5 N( b% ^" p7 U7 |7 W* a1 n@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;
} 效果如下:
1 {( t; Q, ` E
! H. k8 C5 s. r" b' O) O1 i
8 U, q4 P' |: ?4 o$ Y. C8 X2. CSS图像边框3 i5 ~5 W% C1 P" p) \' X4 ]
CSS代码: K! `8 B# n& i) [
#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;
} 效果如下:
' X4 F) N# R4 u# Z/ K! R. a
/ |6 d' K+ r/ v/ o: B, H; _' G. h+ D
) q& f @# i: D3.CSS蛇式边框, G x, G+ t# r& m5 E$ V
CSS代码:
" W5 @# K ~; ~* f#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;
} 效果如下:
' a$ c, \- Y+ s- m) W
+ X( T9 ^6 ~- K* r7 [' z
% ~1 Q7 r- x$ T. d4.CSS阶梯样式边框
0 _6 o% _; ]$ G# sCSS代码:
N" O7 P# A3 a0 H; F4 [+ Q#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
} 效果如下:4 ~' R0 {+ T. h( ?1 O- o( o1 O( D
+ I6 L% U: s* A+ d& _4 d$ `- S! d- j
5.CSS只有阴影边框
8 n2 C4 A3 r- Z, U# o2 b7 dCSS代码:
" b6 u! Z7 O) V#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
2 @: ~( f& O8 e+ u
, J) @: c' k+ Z# K2 O, @
' u& p& t. V1 d% {+ e$ X6.CSS带阴影和轮廓的边框. T* I" d& `- M
CSS代码:! y! E& v# P4 ~* ~7 n4 ]8 E
#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;
} 效果如下:
7 [- @4 g; d4 {6 W6 S! Z, A7 N
$ l+ J) i5 ^) I9 _& r( v6 _, z. W& O, H
7.CSS少量阴影和轮廓的边框
6 I& X1 G. [* S, ^5 [: b+ hCSS代码:& b; Y! Q+ T2 y; f
#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;
} 效果如下:
( E4 n! Y; o& Y% h2 ] o
2 {7 _0 T/ m( Y, f* A
5 ~4 v/ A. }9 \! d6 p/ e/ G6 b8.CSS带有阴影的双边框
- b/ Y2 Q0 }" K5 m# x* ICSS代码:# s* l0 F. J% E3 D9 y. @& M* Z6 c& }% O
#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;
} 效果如下:/ k" ~) R3 }# h
, w2 Q+ z7 J5 S9 q9 M+ v' v3 F- p' |
9.CSS多色边框
1 d9 y3 W" a3 D. o* KCSS代码:; q( ~, |6 o6 q) V7 G" ]
#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;
} 效果如下:
4 U4 A" x& I" @6 L0 o7 k+ G$ [% C
|