CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
/ [$ M3 D/ Q# d 以下各特效用的HTML代码相同:
7 M; }* z1 A' o X<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 7 |9 S" J8 o$ D6 z9 y7 L' M
1. CSS动画边框
1 O' z' b& z$ M5 @: I4 kCSS代码:
! `" d* U" s! l1 \ B@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;
} 效果如下:
4 O) H* p1 W. n) E% K; z
* f- E9 {5 ~4 \# h) n# [2 Y; Q* K* o; a2 v5 F
2. CSS图像边框 `9 q. P' E5 U- c
CSS代码:
/ x0 P9 e9 ?) I2 Z" ?. a#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 b4 r6 [8 \2 _4 R* Z! }
! M; w/ g! d! @; M" f
& X1 H) R2 S: T3.CSS蛇式边框- |; V* w! P, }
CSS代码:
. ?8 `- N/ M0 d. ?/ D#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;
} 效果如下:% b& K, F8 R; T6 V+ P4 z: \ C; U
% {# ]$ c. v7 P/ P4 c8 f
9 n& }/ b/ N# {4.CSS阶梯样式边框
0 Y! I5 w' m- v) | A7 VCSS代码:
5 E1 a4 C N" C" \0 A#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
} 效果如下:
- |" ]( a7 M0 `+ r8 {, D& M
. q- L1 ^3 D0 [; e; n5 n
/ p7 t; o" f/ ?; _1 G0 D
5.CSS只有阴影边框
! P5 t0 t1 Q0 G( |7 I, c. DCSS代码: g/ g6 F9 k, B2 Q5 s5 p* K) J
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
4 i f! `+ p- k
5 _7 t: j# y, k: t- P8 e/ G
4 L8 U D) m d/ c" M% |6.CSS带阴影和轮廓的边框
* }% b! F4 D5 C" ~& `+ PCSS代码:6 I) c& L* Q6 H, D0 T' B/ |
#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;
} 效果如下:3 Q- }* k- o% o& X$ Q4 d
) x' b- F/ p, `8 [+ J6 p% S
: W# g% \0 q: O6 z7.CSS少量阴影和轮廓的边框
2 p$ R4 X, s, I% f2 XCSS代码:* ^4 j X0 s8 I3 K- }0 {( ^: B
#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;
} 效果如下:* F, ^+ u1 ^: O
3 {; a/ }' w+ t$ [6 c
3 G) M. \( u6 Z3 i0 P. b3 y8.CSS带有阴影的双边框
4 w# H5 ~2 A2 h0 T+ ICSS代码:
. I! A$ v0 R M5 }5 C& R% K3 U#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;
} 效果如下:
9 t# s9 s n! m
9 p; m: N; j" o. l! R* ]
% s8 n$ c* \. S9 }; H% z
9.CSS多色边框6 `0 w0 T/ {2 [# q/ T
CSS代码:
! t4 _9 B5 N+ a0 M! a#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;
} 效果如下:
: Z' I2 B/ t# O0 j) Q
|