CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
- ?6 G& f: \3 E+ d% m8 B 以下各特效用的HTML代码相同:3 _( J! _- M& e6 A( p- U7 C
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> * \1 V! Y) j* Y& D) q
1. CSS动画边框* I' W0 e8 `! r/ J, ^ _
CSS代码:
, i2 F9 B; Y' J N3 s+ S. h@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;
} 效果如下: F& B4 x4 X. U: W0 b- ~
/ h3 a" G! E0 W( }4 w: Q8 F
! v& R7 b a' M8 [. D$ H' `
2. CSS图像边框
: b/ \+ r2 @" A# E% H) R( {+ |4 ZCSS代码:/ i# S. K5 R7 G
#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;
} 效果如下:
' G$ `: ?% H4 b9 n( q
4 A: ?( d6 D/ x& S- H r! A: J9 Z/ f- z; t+ l7 W1 ~8 g- u
3.CSS蛇式边框3 y j/ `/ s" [. H- P: X
CSS代码:
2 ] `- `, M, |4 B3 N#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;
} 效果如下: V3 Y/ {' V9 s8 z0 g! k
$ P2 }7 X- n1 Q p& [. |
! j7 d& X9 O) L4.CSS阶梯样式边框/ I/ C/ P3 ~. P. m+ ~# Z/ v
CSS代码:
! n, u$ b# K R) o: w: H; y#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
} 效果如下:
7 u- C0 t# K. A" h
s6 w# v' r. f# l
+ q$ m8 W8 t1 n. c1 V. I5 |
5.CSS只有阴影边框! G/ @$ Q: j* ?
CSS代码:4 X! x/ w( R( F% `3 v& U
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
- j5 ^( q: L& j' {5 D$ Z( n1 O
& l* Z3 a' v5 C; f3 I% u8 K7 N
, G! H! |+ p$ i# [1 M6.CSS带阴影和轮廓的边框. D8 @9 Q6 Y, q& s+ U# G
CSS代码:
% a! a& F+ Y( I+ }1 S- R% \8 ]#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 _" N+ r) n' @4 i. S) C8 X
( x3 |0 V8 d0 g% \, U" A: X- a0 H# E
9 m9 `& Q: [; X* y. O7.CSS少量阴影和轮廓的边框- ?. N9 ?! G, r- {9 M
CSS代码:
8 Q J9 c2 b# X+ h! Q- m#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 [5 m1 [4 M4 e( O" T$ k
+ c% t( I1 q/ r% u D( p
9 n" J8 y o- d; x/ B5 s5 K8.CSS带有阴影的双边框
# v) h( G* g+ E/ c( bCSS代码:
( w& _* d4 F3 q, M#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;
} 效果如下:7 W4 Y+ s6 A7 i8 N: G2 F# [
- _- H' {) w( N7 }/ Y: O8 E% s; ^+ d- i, ^" ^! [0 P! z$ h; Q( L; j2 C
9.CSS多色边框/ H4 X" \2 B8 g$ V
CSS代码:' ~* ?2 a2 v% Y1 ^6 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;
} 效果如下:2 @$ P e; q$ a
|