CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。, I1 u8 q/ S: @. s' V- m( O. b
以下各特效用的HTML代码相同:+ J5 n; `$ k3 ?: |3 y. J
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
! V5 s: B) Q1 u8 C) `1. CSS动画边框
5 J: ]* B8 J2 iCSS代码:0 S# w& I; \5 b- q8 W; O' x- x0 D
@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. e' A# Q7 y
% A* \4 i0 ]% W9 y2 X7 L: D$ V% T& t d! T
2. CSS图像边框( e! `0 m& R0 |0 b
CSS代码:: N1 y$ ]% Y" S2 v4 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;
} 效果如下:) V; j' p6 Z6 ]# m* `
7 v. f0 J4 J* l6 h4 N$ y
7 k5 ^8 F4 _. m9 ]( H* g3.CSS蛇式边框
0 ]8 n( ^( d4 pCSS代码:! f8 w6 C; u. R' G; g
#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;
} 效果如下:1 \# S4 Q% {" i! B5 y- R4 h
/ P) l2 I6 I* m5 Y
7 [: O# O/ E" P4 Z ]# c4.CSS阶梯样式边框' B) W$ _# j B+ Z/ ]' J
CSS代码:
" t5 w3 Q6 }! c) N8 K. 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
} 效果如下:+ s. M$ E; ~" {4 }; z
: h6 k# ~7 `- `8 D% r% o7 }0 G1 e. H% {8 \' i0 Q
5.CSS只有阴影边框7 ^8 q! U0 L% X. a
CSS代码:4 Z. l0 t+ s( J/ R D/ M
#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 e) p o& e1 }1 ^1 r
) W6 H' C6 w# P7 e3 I: Q
D) o* k4 q5 M6.CSS带阴影和轮廓的边框1 z. p2 g$ D1 h* c! o/ O6 Y
CSS代码:; h' {+ J- a& G9 g. }" s' a7 g0 c
#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;
} 效果如下:. @) ^1 G, r E9 [% Y1 `. X
. Q; s L; G# X$ }* E. t1 l
# g% r; Q7 T7 t2 H+ Q0 ^7.CSS少量阴影和轮廓的边框
! Z6 e$ v' }1 QCSS代码:
! t5 f* r, v, p4 k" r4 p. H% ~$ @! s#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;
} 效果如下:. x1 S( ]8 P3 C: y n
* V2 K% ~9 X1 p. h4 E2 i" f
: I3 D+ L1 C: j U- f! e6 m8.CSS带有阴影的双边框; W. F6 b6 A4 n1 X5 k; F
CSS代码:
9 M" G& u( Q p8 x4 D3 a: i- c) G" ]#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;
} 效果如下:
0 e' y5 l* ~5 r; x: t
' P& ?) M( q( v% n [
& Y# E4 l, Y [+ g! g) G' c9.CSS多色边框2 k& _% T4 `1 U% L
CSS代码:
( |) G1 N- E S$ E8 J- e#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;
} 效果如下:
- q2 A: S7 {2 s* v( F8 N! v" d
|