CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。7 B" l3 y+ ]% c
以下各特效用的HTML代码相同:% ~* p" t7 m" y* I0 F
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
! N4 p6 _; c+ p+ n# n+ X' }$ Q( ` 1. CSS动画边框
8 h- n. k6 _& m0 W$ ^5 |( v CSS代码:
4 _% A* @; ~2 O/ R n& T @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;
} 效果如下:8 ?& c5 l1 {3 f, e* b
% M# h! A% d/ [8 z& H
; u x# b0 |5 ^+ T# n" H
2. CSS图像边框 k& ]9 V& F0 _5 i S) m" }, \8 C$ U
CSS代码:- d: O f e. X5 G8 I/ o; q9 c
#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;
} 效果如下:1 f( J' L- `& b- |9 D. k6 U7 m- T% Q" h
`+ g9 s- n" E3 f, }" B4 M; Q4 P % m4 a' Z; O0 e; o
3.CSS蛇式边框
. X5 v3 G9 U' }3 s9 H. ` z. h CSS代码:5 k& a: _, j# r6 y% v
#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;
} 效果如下:8 f) n) t. l. F% d9 S
; c1 O, Z2 p5 R, [
% h) a( L! O, q$ H. J 4.CSS阶梯样式边框
7 V7 @0 r; ^' H& Z2 z. J CSS代码:
' r3 _! ], `6 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
} 效果如下:. N' z$ o. D. }( C$ x
1 q6 e u0 {/ D" [# X
0 E& Y5 Y3 } }. K6 j% G5 q: k 5.CSS只有阴影边框
4 Q# T3 h( d [$ L CSS代码:
0 Z9 Y$ a+ \$ g) z8 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;
} 效果如下:5 U: t! P( O0 [
4 L. V" [$ B, ^- ~
5 b/ R/ J$ s8 V8 j
6.CSS带阴影和轮廓的边框
: I7 B$ c4 t; m( j& b' B CSS代码:
. F5 p9 `5 ], q5 f" a4 }9 f #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;
} 效果如下:
/ I% F2 M( i7 ~6 o
0 i" t1 Y c( V! {7 Z& @ " ^; o/ Y# @# A
7.CSS少量阴影和轮廓的边框
% }1 D" s4 T% V" f CSS代码: [- N- `2 f2 |, h+ a7 |7 }* {0 A5 [
#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;
} 效果如下:/ ? u3 `8 i. b8 t8 Y- I7 `
5 `9 v: e$ b9 m : l) ^$ S7 V8 x% ^7 E, n# b+ f
8.CSS带有阴影的双边框 4 @) N' X7 U) ^3 p& F3 ?
CSS代码:
* e/ y0 `0 \ Q8 U/ G1 I #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;
} 效果如下:
7 s& B) ~# l, J& M; R& u
: Q% M" K1 H, H ; s; k/ q# R+ A& J* x
9.CSS多色边框 8 k3 E% Y1 c0 O9 T$ u; ]8 `6 |
CSS代码:& d' y+ ?& ]( C, p K$ U) P+ v c
#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;
} 效果如下:
$ Z5 T P, I2 I5 H