CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。; F' `) K5 p" b1 Y9 _0 I
以下各特效用的HTML代码相同:+ P' A1 n$ T7 m' z: S3 @6 A4 G
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
8 W2 m/ S8 E8 H9 S2 U- c 1. CSS动画边框 ( H1 u5 s+ }7 u+ b- _5 p
CSS代码:. P" k/ }+ h) s4 R" [0 r2 V
@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;
} 效果如下:# B$ D2 W3 d+ @/ M& M, Z
3 g2 M0 h! w% J& _1 R8 v5 B3 V
+ t# s; k' T' b- |2 l7 |% s. d 2. CSS图像边框 " h3 w- G( ~- b P9 G8 l( k/ T
CSS代码:
6 x& ]% H% Q. e #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 v/ Z V& M# b; ~$ H, `
: y8 g8 I1 Y4 U" w* a3 f
2 i2 `9 H; T& ^4 _" q! s( } 3.CSS蛇式边框 D& m3 A, N/ {
CSS代码:" Q9 V7 W( F# 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;
} 效果如下:# s7 V8 K1 q0 n3 ~9 d
( Z4 J6 F4 ?7 g. d+ c
' r: |* B9 H, W# A5 ^4 S, N 4.CSS阶梯样式边框 # m! E. n( n. J& i m5 |# I
CSS代码:
! G; e7 c+ L8 K* e# n #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
} 效果如下:) X8 H0 ?6 E" N- X& g2 }+ ^
3 T- x' r I% w! n+ O 2 `- b8 A1 C5 H0 ~: b B# K) p
5.CSS只有阴影边框 h: H7 H1 s$ d% x7 U
CSS代码:
: S% [5 U+ V1 J2 c #box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:( G4 |( M* Y, Y3 i
" _" }% n- V: u+ |
0 ^8 l" u9 h' y0 z) Q 6.CSS带阴影和轮廓的边框
* a9 t% J) Q* Y* f. {0 [/ E# k+ x CSS代码:
9 b3 A. M" H, `: v4 _2 J7 t8 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;
} 效果如下:5 r8 x9 O3 K4 x/ k3 M1 f
1 V1 K( x$ Q2 n9 v( }1 @! O
7 r6 ~# @" y+ j, u- `5 @6 Q 7.CSS少量阴影和轮廓的边框
5 h- A4 T+ {, B4 ^6 u0 u0 h CSS代码:
3 h* ]/ t* v; Z$ l #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;
} 效果如下:
' _' i; n' ?& l7 k% E# f Y) g
7 A) ?3 k* p2 u% }1 j5 h1 n+ N- A 1 L" O6 p# e, X! L
8.CSS带有阴影的双边框 / N! X3 W7 B' X/ L; P
CSS代码:
1 V; M. v# |% V1 m* j" a #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;
} 效果如下:, q, ^# |" B$ }( `
: j+ }, K& C5 P; C
5 ~) N8 y- X( y7 \ 9.CSS多色边框 ' N* I4 v+ n# F, P
CSS代码:8 C! M) A6 ^0 S6 P
#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;
} 效果如下:
% J0 [( q, _( B; i: K+ V