CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。' X# l% z9 m4 m1 `& a
以下各特效用的HTML代码相同:2 @9 @- c9 s; h! R" {
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
" _5 Y/ q1 Y/ d$ M) Y1. CSS动画边框$ i" @) G; ^/ z: h( s" r/ c/ a8 O
CSS代码:: f- {* |. t+ f3 a
@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 j0 T( e( B% B) O8 r: q
* z$ j- h* ]/ {( j
5 K, h& g% s2 \2 Z% I
2. CSS图像边框
) f& v: P8 m- R) ~$ x- L( P, E6 oCSS代码:- D5 j4 i1 }* b* X/ j
#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;
} 效果如下:
( O, E( J% S2 X; q3 `
5 @- g, {) ?9 h# h7 N4 k6 g1 D
5 H- F: o0 x; _4 ~6 ~
3.CSS蛇式边框
8 d/ K# t: x. F }( Y6 dCSS代码:
6 P( J! r4 F* Q( v3 d#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;
} 效果如下:# x. @: n+ j; z- f+ ?2 D' \
. X* d$ X l$ X- Q. U7 A1 ]
: R9 V' r+ [! Q' \9 D5 W4.CSS阶梯样式边框3 }6 w) {/ q, M
CSS代码:4 t& T" @+ |2 ?
#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
} 效果如下:" v( i4 m& I) ^% [5 r M
7 i/ \6 P/ }1 D
p0 @" d( u9 {2 E, F: p# W5.CSS只有阴影边框, H6 a2 ]( d+ {3 D: `3 x- o# X. [5 L
CSS代码:
8 Y6 k& ~0 r; R- r6 U# g#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
" G) g m8 X( j( ^4 S
5 o: {* ]9 D6 {3 S! Y/ B7 ]
1 N( c8 P& t% D& w! h6.CSS带阴影和轮廓的边框+ I+ m! C8 V2 u$ A) ?, v
CSS代码:
. i2 t- J6 x4 e K3 ?#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;
} 效果如下:
. l7 `& v9 {9 d0 _5 U" k0 l
* H# `4 D8 f6 O8 X: z0 F" s7 ]1 I' x+ R" ~
7.CSS少量阴影和轮廓的边框
s( ]1 {! Y2 q: v+ eCSS代码:' Q D2 M/ ~& U( ~! w: F
#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;
} 效果如下:4 ]& s9 j! t4 x- C
, K2 }; k3 ] F
( H; y4 f$ r0 k. ]) S) L
8.CSS带有阴影的双边框1 |( I6 G% z/ b4 k6 v: W. ^5 _# z
CSS代码:
% M& P H0 X4 n5 c9 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;
} 效果如下:
8 l% S7 ?% }. m
" N. b/ y6 P a) y# Q2 y7 G# q
8 C" |3 Y7 B: ` C$ ^* k% Q8 W, {$ Y9.CSS多色边框
7 V! X$ Y, Y6 K- x, \% _CSS代码:( L' y$ l Q' [( e Z% p/ D
#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;
} 效果如下:6 X: V8 } y/ T: z! ~5 L6 G3 x7 a
|