CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
2 c; H5 C1 t* {4 Z4 ]" ^- j 以下各特效用的HTML代码相同:
2 r& S5 D! f$ R- C6 @: h& B <div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
* O; Q& Q# ]1 @7 j0 E9 j3 O7 B 1. CSS动画边框 / M+ s6 T# }+ F2 W X
CSS代码:' j1 f$ ]* ?9 [1 R+ A5 |
@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;
} 效果如下:
$ ~, [( x! [, G& N2 o3 A2 I
, i$ @* j" E) o0 V1 N+ B9 z 5 A/ O o9 v5 K
2. CSS图像边框
+ X( t( K4 z% ~9 ^ M CSS代码:
+ C- q- ?! E7 w #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;
} 效果如下:/ U6 @' F( ^4 ~ c; t9 t
n+ `- B" V* `. P3 J 6 ]4 n$ V3 j! e, E
3.CSS蛇式边框
. }& s1 T/ f- k" V CSS代码:/ i4 J! F. a; Q6 o
#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;
} 效果如下:+ |. K. M! R c8 a, W
5 b( o( D0 x; j. [% I- Z v. G i
* a$ m8 H7 ~" ~: A' f; w
4.CSS阶梯样式边框 6 |' C4 p. A1 f" q6 l# ?
CSS代码:
$ g+ F9 w3 O" G# w/ z( y0 r3 \ #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
} 效果如下:' `! j; a* z* Q8 A$ e5 D; P; [1 O
: M' s0 ]/ z# ?6 C( w
3 ?9 K3 B8 v% a4 E 5.CSS只有阴影边框 & T2 g. q4 o+ R
CSS代码:5 u" G! H' ?' M4 e7 l! @% O) O; E3 [+ r% 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;
} 效果如下:
! b. ^# _: |2 m; T8 r
7 y: G0 l0 R8 M. W: c z! e) _' P& _8 u
6.CSS带阴影和轮廓的边框 ' i P/ c1 C# }7 k* X/ I) v
CSS代码:
7 E. w/ u8 a/ @% H #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;
} 效果如下:. Y% U; s- ?/ q4 Q7 [$ \5 O
) U, K6 a' L& x* ]/ U$ K
( D" m* k0 r8 R! x' B 7.CSS少量阴影和轮廓的边框 . n+ K- N, Q$ U A4 L( f1 Y% F
CSS代码:
6 ~ S1 v- A3 u" {, I. Q% G #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;
} 效果如下:8 @) a# j4 K2 O( |
& f! e4 u, g1 F- n
2 A' }/ Y6 A- V! K8 A6 @; @8 f
8.CSS带有阴影的双边框
+ G: M. b2 Y/ d$ S, O7 E CSS代码:* s7 D; N' X; ] \
#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 Y5 g! N1 t0 }
, d' d4 P/ T" i$ U2 u) N/ D
& T# n' m- R9 u$ p 9.CSS多色边框
; n7 Z# ?9 J% U9 j9 t8 x CSS代码:
. G1 |" G G% _5 V! ? #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;
} 效果如下:
8 y# m" Q+ `9 \( G7 H2 C" P& h