CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。' t) q- }" l) W- n# d2 R a; e. c8 c
以下各特效用的HTML代码相同:
+ `9 ]2 l2 W4 z. M<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
# C- X! ^( ]5 {6 c9 @7 @: X, [/ B1. CSS动画边框* e4 ~+ V, o! F! U" T/ x3 ]
CSS代码: E3 t2 Z- G8 D' _
@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 p1 \8 j, \# K& j
6 T, Q# f- l- |9 @! W
) P, [$ m, U! v$ F3 u
2. CSS图像边框
: s' T% f4 ~9 yCSS代码:$ o H. x9 M2 }+ K3 T
#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;
} 效果如下:
4 p1 e8 p* B( h! Z7 y
$ F, T# `- g$ Q
6 k# j# s9 [+ u3.CSS蛇式边框
+ g$ l: c7 a, |0 ^9 E$ R: vCSS代码: t& [" X G+ X- Z; }" w6 V2 S
#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;
} 效果如下:
) A1 R$ d, D4 C9 r' Q' Q
( e. b0 `9 A" m* d& [
+ U3 {3 k8 {- v/ x. I4 t4.CSS阶梯样式边框
" }; O$ m& W5 uCSS代码:( ]- b- w1 j4 R+ T' c/ U
#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
} 效果如下:' B+ s5 T V3 @0 V
& d# D9 |- U- D [
) h- T! Z* P6 @5 K4 B8 e
5.CSS只有阴影边框
* c2 u% n1 T0 C2 M) [- L* a4 BCSS代码:' |: q& W( [+ {9 P. D
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:& ^' Q8 ?; Y# {7 \1 W
" l) J0 n/ M4 t3 w6 N' [
1 D- L' v- q% D6 {6.CSS带阴影和轮廓的边框& H) d# z0 G" N p! E; |8 Q
CSS代码:
& f4 c5 z+ O. A8 }% n$ 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;
} 效果如下:
7 c1 t4 J6 F& `/ M; I$ D: b) F
+ G% | {' \4 y9 G
* B7 ?( K! }) P2 d% ?
7.CSS少量阴影和轮廓的边框
. M+ i/ {9 C7 i6 d9 V" y, ACSS代码:
( T l4 X! u8 B8 \#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;
} 效果如下:9 E- m b" i8 p. k$ w( Z: _# r
. ~- Y' u1 H. o; r
. H- `9 V4 u' L W3 N7 L$ r8.CSS带有阴影的双边框4 S- [3 g3 y, f1 r: Z% g1 H$ }
CSS代码: N; `. {3 Z8 s
#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 ?9 z2 [% E8 M8 n* ]! o
4 _. b! Z; v/ R9 y
6 G: ]# R% n6 t; n: I, R9.CSS多色边框
, U' c4 N7 z" l! J, d: D4 ?- A4 ?- DCSS代码:
0 s) u, H3 l4 @#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;
} 效果如下:3 a9 X) U4 K4 x L5 m) J) w3 i. _
|