CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
; L$ J t7 n5 |; l 以下各特效用的HTML代码相同:6 }: D5 k+ D j1 g7 E% V
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
; V" [+ T9 U2 ?7 z: W+ n: I( ?2 j1. CSS动画边框
. c6 c% `5 N; d/ T( C6 {% @CSS代码:
& B6 i* Y& Y: ^@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;
} 效果如下:
( E/ y- [$ }+ {8 _: a; {! n# }2 T
* C8 O$ k6 Y, q0 r0 ^, D
0 u, z$ s# }9 E8 W
2. CSS图像边框
9 X# u8 U/ F+ [& z9 t6 @CSS代码:3 I4 D9 b+ N: f R
#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;
} 效果如下:
4 S( d+ E4 G) R! z
! V! @8 |* I* l
' S) |* I( @/ O$ H* C) K
3.CSS蛇式边框# q4 T' m5 F/ }) g9 V& O
CSS代码:" E9 J$ X( y8 s- G/ L, A
#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;
} 效果如下:
: {7 X3 W9 |! {/ q
# w m# w% b9 v% F: |) j2 e% u+ y$ s
4.CSS阶梯样式边框4 y/ B2 S, _1 d2 D8 N, Y
CSS代码:
5 P. r* `$ o2 ?( G# q- {+ k) C#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
} 效果如下:) L! x: E. [6 B# B
. h' C4 r0 v* N1 |: G- c$ N4 k" p0 Q) u. ^5 i) S
5.CSS只有阴影边框( R) x6 t1 x7 Z: W* ~" C% j
CSS代码:
# M) x1 E2 t8 p#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:% M9 j8 E& x( n; I4 n: m* A1 N
, }1 w$ p2 Y9 _
( |2 k+ Q4 ]( l* u* Q4 ?$ }) l5 f" s
6.CSS带阴影和轮廓的边框
5 ?9 G. }$ h- i1 l# QCSS代码:- f, U. ]4 X" G, ?
#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;
} 效果如下:
/ T a5 d9 [+ O
; K& ?- U9 F+ U! w
, V& \ F- N2 G7.CSS少量阴影和轮廓的边框
7 H0 D/ c: C& F7 DCSS代码:
# y9 {% V! Q- G. _" `& t3 Y* F; Y+ 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;
} 效果如下:
u5 T6 C; e7 E6 S
$ P( }3 {+ z- ~+ i+ m+ E b8 [
- Z/ ]# s* N1 `* n t+ V1 U& d" a
8.CSS带有阴影的双边框$ `3 ]5 T( p- z; J( q% ?* `' D6 g) G
CSS代码:& X# L, H# ~9 h6 J, f
#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;
} 效果如下:
1 O! Q% s! k, C" b' b2 u# J
; V/ A. L) d, p' O
& P F- w% z) P' p% @( X9.CSS多色边框
$ O+ K2 ]6 S9 o) V3 rCSS代码:, p2 A9 R6 c x- H6 Y H0 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;
} 效果如下:4 w0 n2 O* {& ~$ U$ T6 v
|