CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
5 O& r- n, _& |8 s2 o# l2 c 以下各特效用的HTML代码相同:
6 X" E/ o. {- ] B7 B" {<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 7 y" r. H i, c
1. CSS动画边框5 f% H5 h7 q: C1 w2 O m; U/ i
CSS代码:
/ }, l6 x1 T9 G. A3 c* @@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 m+ `6 Q1 R7 R. A; m
. Q/ n* k7 j! v# K) h; ?* q5 {; e! U% n0 j8 l
2. CSS图像边框9 ?. O1 k* [1 S
CSS代码:3 T, k3 w8 r' A7 Q- \+ f
#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;
} 效果如下:
0 ?( Y2 g- o( R/ X8 ~
9 q3 F( D: E& h! e: n J4 t
2 z' ^% g/ F, {" X6 w) H3.CSS蛇式边框# D% a0 U) \/ c' z/ o. U1 h
CSS代码:& J) s' m, x2 e9 u4 }
#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;
} 效果如下:/ S6 e9 \! S" K$ Y
3 ^4 `5 [# }# y" z v- t
# v) S; M1 S. c- \
4.CSS阶梯样式边框5 a$ u$ S7 v( m4 s' D
CSS代码:
" [$ A# s# I. x. D5 {+ T! K6 F$ ]3 A#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
} 效果如下:
5 M# x1 x" r3 \: ~+ J ?
6 p4 |( S0 |' n$ b9 X
" @0 K3 s/ T4 U3 Z: `( N& \5.CSS只有阴影边框
( k9 C1 J1 d1 K5 i0 o' hCSS代码:
/ [6 G' \' l0 o" B+ M' T#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 V4 q M4 n: V* G
& D9 o% v T$ j9 h( N, V$ e
2 F- ?9 U' _/ J+ x, | [$ `6.CSS带阴影和轮廓的边框
; \! B8 Q* ?; J# S4 l% P+ SCSS代码:( Z3 y% e( z% W$ r0 w0 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;
} 效果如下:
5 t& o0 R2 Z# ]1 o& w9 }+ T
/ J0 j; `9 X4 o d% Y* U( O
6 v3 K" \* |# n- a3 F$ K% P+ K
7.CSS少量阴影和轮廓的边框
" |5 ^3 u; Y' \7 cCSS代码:$ D i( d; @8 L7 ~! 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;
} 效果如下:
+ z3 L! ~; d! Q; N! P5 W0 w
! a, ~: i; y3 {& j/ G) u! n9 t6 p' c6 {- {( U% \
8.CSS带有阴影的双边框
4 Z) n: |$ I1 lCSS代码:
! s. H5 t% G7 ~1 I#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;
} 效果如下:3 }2 z# x% ^; K
J! y3 [/ P( A. d% T
# p' S& b3 w9 a& o7 q+ s" w' C
9.CSS多色边框$ E4 {* X. }8 P5 `" ^% v3 B( n6 S
CSS代码:2 u4 e1 [% a/ x# w; ~* r
#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;
} 效果如下:. t, n( D$ J+ y: C; U8 e& p5 u! q
|