CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
; H- Q r3 {/ f+ _% U& t* A" M 以下各特效用的HTML代码相同:# t7 ]# Y+ V; o1 l+ u" e, A
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> Y; X8 P, l7 k" i+ ^
1. CSS动画边框
) ~: B# L! M8 B0 XCSS代码:
) s& `% B* e8 ]% F& L- _@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;
} 效果如下:% E7 a2 }& |- _% Q* P6 o+ D
1 v2 S) f. C8 d% }6 [4 U' n
) S8 }( N$ u/ f7 F8 r" F, {2. CSS图像边框; Z% I7 K5 _$ @4 L# x( f* L1 z
CSS代码:
' @/ X0 |* o* x* D0 V) |#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;
} 效果如下:
& ~+ j7 s- W- n' o& i8 P% R) u
2 U$ \, [4 M* _2 }5 G
P2 O! A1 ~0 n# Z# B# ^# S3.CSS蛇式边框
# K' p$ M7 u5 yCSS代码:! h4 r4 i5 t; R- {! 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;
} 效果如下:! z$ s4 ]1 K/ q9 W+ A3 j
8 Z4 C* J5 p- w6 l0 r: e9 \& A- [
0 y! h# T5 P" ^) O$ r( C
4.CSS阶梯样式边框% ]8 x! b! Z" {4 V. {; V
CSS代码:
+ M' u' r* i1 `' F2 Y& ]#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 }; t1 v# D1 B6 y A
3 R+ G( \0 b- ?- E) x. f: `& H% Y& M# s
5.CSS只有阴影边框) |1 t3 T/ O' X" s. L: x$ s
CSS代码:& P: n) Z2 `" e S! B4 Y+ D- y
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:4 g( L. s2 n+ T- ~/ D$ n, L
7 i% G& M. X8 I# v; p2 H
6 |% l$ Y; T0 g% x. R$ |7 c6.CSS带阴影和轮廓的边框% \. V8 j/ F E9 d
CSS代码:
! _0 |* J- p$ ~" y5 u8 `+ q7 K#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;
} 效果如下:1 q0 T" Y# g# Y( K" w. H1 I
; a2 L5 h1 ~+ n5 Y" n
8 W# F& y/ [9 A6 r" s0 u: |7.CSS少量阴影和轮廓的边框
& B4 o* t1 X1 J, N1 ^CSS代码:
1 Q% J* r1 h/ a! j9 V#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 @: ~' I D, ?8 Y
0 `1 X7 T X* s. E, P6 S! S
3 H7 {# p6 E6 L
8.CSS带有阴影的双边框 Y' U, X) \# |, \
CSS代码:
3 e' ]7 _# z8 u: u" ?2 X0 w, `, \#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;
} 效果如下:9 Z- V2 `9 ]/ y, G. B$ x9 L
: O: p' J5 |2 q
% I0 J6 f! J* X- r& c e' _9.CSS多色边框8 u/ z; \9 T, s N6 m
CSS代码:* G5 q( g' I& e# T& t' L# y
#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;
} 效果如下:% @- h6 G. }/ k1 J5 Y
|