CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
0 }- W# A, H9 z- N1 A 以下各特效用的HTML代码相同:
* `; V3 G J8 u6 A1 u<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 5 D. _1 J$ z. @5 y5 e7 |
1. CSS动画边框/ U) u' i( n1 {
CSS代码:
6 [( ?" c9 |. v! 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;
} 效果如下:8 Z" }6 j; X% f( F) G2 `( W
5 e X/ A! n8 O- ~) g6 E
% C+ m. O1 ^# d; u `
2. CSS图像边框
8 b+ W" V: ?5 VCSS代码:* A) N0 E" n4 }; l3 g. C! [4 ]
#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;
} 效果如下:" ~+ V7 H7 f, _3 G( J% |
S6 s7 t' u) E7 a) v. a X
' b* L9 S F5 C, m8 B" n& S3.CSS蛇式边框
8 Y0 t6 K3 a1 _' |CSS代码:4 J6 x5 ~2 p" W+ {; q8 a% b2 n/ t+ ~
#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;
} 效果如下:
; w+ H& l- Y# P+ Y6 e) K
# g4 _+ c4 X7 f [' \% {/ D) {9 P% V7 U& h5 E; R- C
4.CSS阶梯样式边框
( s% z, ^- p" ?/ h0 @CSS代码:
* g" h$ _$ ^2 r# J# r#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
} 效果如下:
, s. Q( o; l p% c0 P
: W8 P( ~: u/ B( `- g1 W
7 u; |( E6 Y+ y% ?) J: `5.CSS只有阴影边框
& o. d; _# ^* Z, R* Z$ y2 |CSS代码:% ^- B/ ^5 v( _& |7 }
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:. s: W0 V1 L5 |6 ~, Y! y5 K6 t
) O6 ]- R0 n- _7 }7 H1 b4 g
" K8 \* y, S9 U ?, l; \6.CSS带阴影和轮廓的边框: @) _, Z; Z( x
CSS代码:7 Q+ D+ E0 j: @* B6 h0 X- Z 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;
} 效果如下:
0 c- o$ L7 M: N5 X
; M. |& g# r3 F5 D
3 E+ f9 }2 m, S7.CSS少量阴影和轮廓的边框/ p! _: ?9 g5 ?# C, C- [# q9 Z
CSS代码:
+ f' W! o9 k3 K7 }. {; w/ E; y#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;
} 效果如下:
5 G! i7 m8 Q2 s' c/ A, @4 c
9 {6 L0 O( d" k+ I. U# K
1 y3 R2 ^( X; ?/ @
8.CSS带有阴影的双边框0 G( a9 N. E# x/ m) t! y
CSS代码:
$ H+ A w: @" r3 e! c#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;
} 效果如下:$ ]' k2 j8 ]. U# ?
1 c% T; \4 `9 |" b
8 v6 [5 q9 J) _+ g
9.CSS多色边框
$ l% ?. C: v qCSS代码:4 U' L; d; U9 J0 `0 L
#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;
} 效果如下:5 @4 W1 Q# w w" e2 S
|