CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
9 |/ N' b7 I# v# y; }7 Z 以下各特效用的HTML代码相同:) L) N$ q3 x$ e+ \9 [7 r
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 8 G; P; B5 X! e
1. CSS动画边框3 n0 z) V+ J2 P4 P7 T2 y
CSS代码:
7 q4 ], E! M* \/ x/ ^ 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;
} 效果如下:' z. [5 V. m! v/ O# o7 D9 g: @
+ F! p8 G0 E1 w e' S- x
6 f4 {1 J# d5 ^9 S! V# ?" S! b1 l' g
2. CSS图像边框0 y" {9 \" |4 O1 j7 N; k* N
CSS代码:
4 [% d2 N/ y. [) r2 v* T/ t9 O#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;
} 效果如下:
+ _' V2 W! U) q7 I
* }) @9 V; x( P ]+ }
/ c# m3 y/ f5 M0 i5 O* q3.CSS蛇式边框
* v# x+ D: X% X7 W$ X# uCSS代码:# w. h( C0 K7 E$ r- I: W
#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;
} 效果如下:' P* u: i; P8 s/ t& S& W( }2 K
2 r2 t- v, v% z ^+ p4 i* V
7 D& |. d! W. r+ _! P, u4 k
4.CSS阶梯样式边框& n; g& n9 c, }& x. l
CSS代码:
) E$ N Q% z' e# E#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 E$ V* X8 g- o7 l' [- N# m: k" `! \
' [1 j( C) X3 U1 I6 K' j6 K3 W
; Y# y7 p! r: {% W* W5.CSS只有阴影边框
+ Y7 z+ H/ w/ b5 l3 i; P8 U/ zCSS代码:
3 H: l+ B- o& C/ ?2 O7 i#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:8 N4 J$ |1 c; p) n1 G. x
6 X7 X6 d6 t& H/ Q, j
6 V" E9 S: v- c) t+ d
6.CSS带阴影和轮廓的边框3 F0 o5 ?2 R- ~
CSS代码:) Z. o* Z, L/ \
#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;
} 效果如下:
8 m& o6 W6 ~/ T4 |8 q
7 C* w; o3 w- l6 Q9 }
7 V# p: R1 _' e( e. ?- }7.CSS少量阴影和轮廓的边框1 p; l/ d, {3 E; ]0 m
CSS代码:. O3 c9 M4 a) g8 {0 @ Z: U( t
#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;
} 效果如下:
2 m' I, e3 Y7 ?" B0 ]' y0 g
! l% T. K+ Z7 i# m, V2 h
2 ?2 C- |' U; i" G
8.CSS带有阴影的双边框& A$ f1 M! ?( _$ b' B3 [
CSS代码:
, F0 E/ _' u" F% {# `#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;
} 效果如下:; l6 y( y* n* m( ~# V6 C
9 |# _2 {" v# D% p) p0 b) K' k: y
( {$ ^' C5 y) _; T' U
9.CSS多色边框
: y3 |; H; a. o. U9 m% yCSS代码:' R5 {- u7 H0 X( `1 M( W
#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' O- x( Q# g+ V; e. Y
|