CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。, f$ m. V6 v$ @, _0 b* ?+ `
以下各特效用的HTML代码相同:- l! H% T5 m3 M `* j- d l
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
) N3 q" |# g/ \ V. c1. CSS动画边框7 Z7 ~5 }6 U: N' e! z+ h0 h+ G
CSS代码:/ u8 m4 g1 L Y
@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;
} 效果如下:
) u' n& X- Q% r% f7 g% g3 u6 D
/ _. R9 t3 G1 ^ Q9 t
' E2 M/ l' `4 ~8 C2. CSS图像边框
5 U+ O4 s C8 ]. z3 A ?, Y* @CSS代码:' {& H4 m$ c. D5 m
#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;
} 效果如下:5 p2 v }& u/ h
; ~0 k3 K2 @2 P& o. S! G+ A! f2 M9 B3 A% y
3.CSS蛇式边框# s9 N$ w5 n$ O: d% c7 W
CSS代码:9 o9 @/ p4 m) c1 v d. x
#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;
} 效果如下: b4 u$ {' H* c2 V( v# U0 s
3 Q( j. n- Q5 V s. ^8 a7 Q# `& x' G$ W( c, @& h; |, y
4.CSS阶梯样式边框" f* L" ^5 M. B- r
CSS代码:
" U7 U1 h3 o, }. f! x( e#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
} 效果如下:
2 Y- ^5 X$ K0 d7 \4 Q
/ s o; G8 }3 U1 `: r8 j0 E
+ V4 l" r! R: r. d) N: u+ g; D
5.CSS只有阴影边框
) _+ p, {8 k7 y# k7 P$ X/ s& MCSS代码:& B8 f2 L' @4 C+ I5 b
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:/ o2 r9 w K. ~+ q# G: j
, z& y6 @2 ?: h- a: s2 |
4 z, O- ^; q/ ?8 J
6.CSS带阴影和轮廓的边框 n% Q4 G( Y4 }7 w. A F% Q
CSS代码:
. M& R! w' r- |* D#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;
} 效果如下:: T) _% o* q( Q9 D; J9 `7 j
# k; _: ^5 p, h5 R4 h B
# O0 g. V0 z, U: R
7.CSS少量阴影和轮廓的边框+ p$ ^3 C" F& L8 I( Y
CSS代码:& N! N- @0 S' U7 I( |$ V
#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;
} 效果如下:# r& x8 M4 e j5 a5 z
9 Z& h8 Y' Q% k
- ]4 N" Z# G5 |% c
8.CSS带有阴影的双边框
- x; w8 w% d+ v: V# H: \1 Q: R9 ICSS代码:
3 l+ a, n0 p/ c1 w6 U* w#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 ?4 d: L6 `7 M! c
* x$ a0 h% {- R' U
# x# I; d, T; j+ o+ ?5 s7 S
9.CSS多色边框8 r9 X5 j& R& o+ g/ N2 b
CSS代码:# Y S- v# V# y w9 {6 d6 F8 @
#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;
} 效果如下:
* e' M3 r7 T8 l$ [
|