CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
: e! {9 t& p2 k/ h( { 以下各特效用的HTML代码相同:" t1 R$ a6 z, l2 f/ K) d+ L% O
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
r7 `/ D2 j4 V" l6 Q: L) G9 G1. CSS动画边框
- f3 V M, P" p/ W4 U, O7 `) FCSS代码:; S: h8 Z+ E: F# j' d1 Z! A# r! O
@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;
} 效果如下:9 \0 a8 Y. x+ N# |" ]
' j! L/ a Y; Z& q0 J Z) j. w& Q% T! b! f: E7 m' C
2. CSS图像边框
9 R+ M9 G4 k, J. wCSS代码:
$ d' C! `) v2 @* O. Q) O- V#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;
} 效果如下:
3 z- O3 ]# ?9 T6 M3 v. G6 b0 {
/ i* m* W4 c+ [
7 t( |9 `9 j: e8 k/ ~9 F3.CSS蛇式边框( A& B# B+ O9 @: d' [. c
CSS代码:9 ^' O6 l% N. ]
#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;
} 效果如下:, d7 t8 k6 e5 t
1 X7 ?7 W7 }: d# g/ D
3 A# ]+ u4 a7 @( @4.CSS阶梯样式边框7 e$ M O. D. t# y! w
CSS代码:
+ p. y- V$ m5 a& R3 l6 j' A: X#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
} 效果如下:
* s7 W s$ S; q0 n6 Z; z: l
G S/ _# C1 _; O3 q
3 f) e9 @- B5 o+ o# e# K7 S5.CSS只有阴影边框
2 }( g0 g. \3 Y; RCSS代码:$ i5 z5 E8 r. Q2 y2 P% G+ [
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
7 e$ d x& D m) ?
3 t6 P# J( I$ y$ B# A
" l2 Z/ Y5 D9 T2 q T6 d" {0 c) Z6.CSS带阴影和轮廓的边框
0 i) V+ k" {5 c, q) F; VCSS代码:* B7 P. z- k& U2 J- e
#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 R) |1 A0 y/ h' ^3 ~7 @, a
1 o! L+ a' ~! Y0 [( L& d& K' |2 ?4 @) c# l3 {
7.CSS少量阴影和轮廓的边框$ P+ p) }2 P- U. O! W; w6 I
CSS代码:
, U3 L) L0 u. {+ H6 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;
} 效果如下:
7 S8 s4 I& c7 ]# i5 m* z# y) `
W4 F/ r- l" N) X: N2 g) b D$ r! x
8.CSS带有阴影的双边框8 K1 {* J H2 I, O t9 `* b7 X
CSS代码:9 R$ y: ?) ?( \+ v, 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;
} 效果如下:8 w: Y- x* ` s6 P% A
3 u, r7 `! u- ] `
" g9 o6 X3 D2 e( i$ C9 w- {9.CSS多色边框7 B$ {1 C3 G9 W7 @' ^% _& c8 e
CSS代码:
% {3 z3 _$ T7 ?& r" u' 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;
} 效果如下:
) ]! b3 W9 Q M" a
|