CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。8 d2 |! B+ M& q! f8 ]0 l7 |
以下各特效用的HTML代码相同:
5 R2 C( V: E+ o( y \+ T<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
8 c) R) u: k9 z6 M1 E1. CSS动画边框
$ O, t/ s8 E% `CSS代码:
7 ]3 |7 [$ L' l@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;
} 效果如下:& T: ?6 a! l. ~9 Y& n4 G) d% Z
* n: g' O1 p$ P9 N: ?
" S8 {' B: T+ E) B6 b7 z2. CSS图像边框
6 G( s* k* v: K" E1 h' vCSS代码:
" A5 A* V) {6 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;
} 效果如下:7 k0 Z5 l$ X% h2 r2 F& p3 R
/ s( B' |& R" M
; H& F( S+ t; i7 Y$ c! }) t3.CSS蛇式边框
- T2 C5 l& Y7 `* R) W3 E; @CSS代码:
; C, K' w0 ]% k0 \7 { Z#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;
} 效果如下:) j& P0 F# T; V) V5 x( H
$ L) M; I. A4 g+ ^4 K4 P4 [5 Z- p+ A2 J
4.CSS阶梯样式边框& j; z1 K! Z/ p$ C& |3 Y
CSS代码:
* f/ E3 A# ~4 L! r) f" \& _#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
} 效果如下:
6 W& c W% d7 p( U3 q1 b
! H1 e: p2 @* n3 c1 i
- o" m! m5 H) c, G% o F/ \5 |5.CSS只有阴影边框
+ {" H4 T! L4 z R1 n/ O" g- D$ S8 ~CSS代码:. {2 U g7 H% T8 {, h' F
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:, A* \9 r3 d" k6 c& O
& N$ a6 m; j; ~9 W6 |: Z
( t& ?/ u6 X( t2 u" l. j+ x) S6.CSS带阴影和轮廓的边框; x' S* n, c8 s
CSS代码:. Y. I# n5 j1 E4 z2 l
#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;
} 效果如下:9 ~; b9 f* p+ A+ x; r
, q9 i0 a, |+ K# r" N
( F6 }* w: |9 B& u4 c, o7.CSS少量阴影和轮廓的边框
2 {1 y. n( Y+ ^0 y$ ACSS代码:
+ \$ J: b; T7 f! a/ N) m( T#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;
} 效果如下:2 B" a B. [: ]+ U$ }3 X: v8 N2 m
* G' S8 M: \+ x
; t' {+ X; v4 _0 ~6 y: A, m8.CSS带有阴影的双边框, X" B |% E7 x( i4 W
CSS代码:! f; F9 Y" q9 Q/ N
#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;
} 效果如下:
% w4 V i- {" z, p+ W8 C' d
8 @3 ?8 T0 j7 t4 n! E+ l
9 r/ H. }: z/ X9.CSS多色边框$ _( j) M: p& J4 S/ I/ n) g3 @
CSS代码:
6 o1 I) r: I6 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;
} 效果如下:+ Z% P' D0 d; T; r, _- l
|