CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
7 `6 T$ W* m: B: i 以下各特效用的HTML代码相同:( I5 T: i, X% u9 O; Z) |" U
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
5 u% T$ w8 q1 S( d, s1. CSS动画边框5 G% X$ g& e1 w5 p% e
CSS代码:
1 X7 p+ P+ B2 \# f@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;
} 效果如下:
. e7 U0 G& C& y5 w
* A2 J. ~) _( N c0 b5 v
W: `. V5 S2 Y: i1 Q; b8 x( a2. CSS图像边框
3 W7 _( [5 S4 E! y) U/ QCSS代码:
4 b b, Q/ l# V1 Z9 P) s) Z. M#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;
} 效果如下:
8 E/ ~1 Z2 Z- J1 B
7 S. \9 n+ y! H+ B4 d
! I- Q7 A* A% v# O0 e3.CSS蛇式边框/ @& K5 ~4 k+ w" u) ~5 l2 p
CSS代码:
, R) g: e- W2 @#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;
} 效果如下:
! b+ Y' ~& N+ c* _! U# k
5 Z3 e& V: X6 ~3 t( {" o _
0 B: E; Q9 h# M; I( q; D4.CSS阶梯样式边框
7 @5 C; l5 | ?+ x1 i+ _- `CSS代码:$ @+ ^- G6 m5 ]
#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
} 效果如下:' h& z2 l% B* S* a
* y6 {5 `$ `: C, y
6 q! H8 I5 {( i8 s
5.CSS只有阴影边框
! ]9 i% B( U" L# ZCSS代码:: {) T- S- N/ p) t, _8 H
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:. U: H" ^& ?0 q( {( m
. V+ @7 {8 {) f* _' `
' f1 w$ K/ g9 x, Q5 F6.CSS带阴影和轮廓的边框& s5 [1 W( h% W
CSS代码:
: [! ~" [/ A0 z; `# C7 | M4 W#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;
} 效果如下:
/ x" X w( Z8 \! h: J
3 O2 H( @3 ^6 S) {, i3 M
6 O) x) F& h& }8 Y- q8 q7.CSS少量阴影和轮廓的边框- u$ q# I' u+ r0 Z* W- W- v: B4 {
CSS代码:) V5 {( w; J) `7 r; M# b2 U
#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;
} 效果如下:7 ?! I: ~- B$ W6 E! C- a
! U" M- W. b B7 y3 X' y
2 S# L. f( G! y7 p
8.CSS带有阴影的双边框
! s6 G+ P- k) m: ECSS代码:( c+ v. Z- F+ Q' S- `3 U
#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;
} 效果如下:- D% g: Z# @( O* h$ ?. Q3 \( p. z; {
% k1 ~' B6 `, J9 s+ Y( Q2 ]' d: r; j( @* W& V. O
9.CSS多色边框: x3 p! T: b* r) x# F8 y
CSS代码:2 L$ [. t+ r6 Z: m
#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 @' b, ]1 H! B. \. ~
|