CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。) A* u; n- E3 r. E! w' I. [
以下各特效用的HTML代码相同:
* Y/ ~% B: D* s& s$ H% c! n<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
* w7 D+ Q6 {3 c+ y' N2 H u5 _# z1. CSS动画边框
/ G6 \( ?) r9 M# }" C7 @CSS代码:5 T$ P4 t7 P3 \7 d7 _
@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;
} 效果如下:
1 G1 M5 h. r5 D4 K7 V' k
T+ E5 q2 w8 d9 D1 o! G3 V: y. w- u" j/ }6 [! R% u
2. CSS图像边框
7 D" q! e. N" b ^- L' nCSS代码:
: K- `5 |6 A* [" c" p, y6 B. F#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;
} 效果如下:
) l3 X5 v$ j, O3 @5 X, b
6 y# e5 J3 x9 z+ Q$ R. x6 j1 o+ ?6 ]: k& \1 t1 u
3.CSS蛇式边框7 \) i- s2 ]9 e
CSS代码:3 Y, n# Z+ m/ j, H
#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;
} 效果如下:, a8 o z! B) ^ \
" G9 R# _0 m: b& \
/ A: e: B* P/ Q/ }) j$ g( A4.CSS阶梯样式边框
* n5 f3 ~4 W, i7 D8 s$ e9 ~CSS代码:7 ~" ~* l: _( n6 g$ M) |* O
#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
} 效果如下:
0 l! R! z- @0 J, _
3 D: a0 Z% a! K5 f4 M. D5 `# h: W2 Y
1 a N d( \0 Y" h5.CSS只有阴影边框# U+ _7 t0 ]$ r7 d, f
CSS代码:+ h! Q O; \7 P8 D: Y: ?# ]( j' X# ^
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
/ N; M) U+ J% s- b1 |3 a6 ]
. u. W- v) k j: q1 Q8 E: u3 M2 v1 O ~5 N% b& _' k
6.CSS带阴影和轮廓的边框: |% F9 B0 S4 ^! D
CSS代码:
. J7 M9 i# {) K5 A3 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;
} 效果如下: Q- `5 x6 C4 N2 ~* x9 g6 |8 m1 h
! T J4 F% U/ ]% K9 R' f/ Z
8 g: R }9 {; R0 C4 {+ ]' ~7.CSS少量阴影和轮廓的边框, G6 _* J( W) J! Z7 y5 S% a; b/ W- g
CSS代码:
( E3 n% O8 f6 }6 V( d; W#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;
} 效果如下:
; M O R9 n. H; g; R0 O0 X
8 E6 ^; Z1 i# x+ y; Z$ R) y$ d5 U2 A. Y: `! S+ I
8.CSS带有阴影的双边框4 I O* Q* v2 ]3 P
CSS代码:% ?+ e+ u! b. d5 O( Q
#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;
} 效果如下:2 g6 Z5 X; t4 y9 E, V8 S" p
( v8 \2 u; i; }( d
0 s Z% E6 s' h8 s5 B, w( ?9.CSS多色边框
; y: o* m: f7 W$ B( {CSS代码:% c) J+ S7 k0 P' D, P# Y8 z. t
#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;
} 效果如下:
* L- G& V2 P7 R, i
|