CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。1 K' M) F. o- r: r9 B/ ^
以下各特效用的HTML代码相同:
. @+ H' @6 r% O0 Z) H! @; h9 A <div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
& W- |! P! ~) c 1. CSS动画边框 - j# i# K/ R2 p9 ^ ~
CSS代码:
# W8 G# M& j; z2 ] @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;
} 效果如下:
$ q ?6 f- S! ?7 _* d |9 k6 C
2 U6 H7 u( s3 g5 u
. b3 T( J: u" Y- @' W
2. CSS图像边框
" ?. C, D: l% ?! `% C+ ^ CSS代码:
j) k8 L6 t! ~3 x j: N #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;
} 效果如下:
+ l+ ?: J8 D4 Q' p$ F
! s6 Z& X# ~* e! q9 _
& \2 a+ g9 t, ?) x: A2 a
3.CSS蛇式边框 . d$ r- h. i8 `$ e# X2 `; c7 q' L
CSS代码:
4 S! R& u$ |, Z5 E7 x/ |. k3 M #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;
} 效果如下:
7 x% k; Z6 c& K6 w
+ y# j" ?5 |& V% S' v0 {0 M
; |0 ^0 q# v( R( x, I 4.CSS阶梯样式边框 # Y$ v6 _1 R; j- x* J
CSS代码:
' T$ x0 Y' {/ Z% 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
} 效果如下:4 b3 s G- n* H# b
# b& W1 i7 X8 F q; v5 I6 ^+ e
3 B3 V* B0 U7 L% V2 ^6 i 5.CSS只有阴影边框
' B- ?% o% m4 Q- x& U+ Z CSS代码:( D4 C3 W B" u: N, w9 j w
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
# x! E; S4 ~$ H. X* ] H& o0 b6 h) E
) P9 t$ Y3 \" L2 i; t : k+ g) h% c! x# d1 D" |
6.CSS带阴影和轮廓的边框 - Z8 v4 s3 J$ _) B- b& }. \
CSS代码:8 {( \5 e p/ E" _- a+ J0 M
#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;
} 效果如下:
" o2 P* Y5 h' Y6 o$ T
8 D) F1 m1 ~1 s, k) m+ T
; a6 |# y) @2 B' ~* a/ x9 |
7.CSS少量阴影和轮廓的边框 % n: Z) k% z: P& Z1 D3 P- C
CSS代码:
4 q3 D, w4 {" _, Q #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;
} 效果如下:
$ b3 L5 f; S; S/ l8 V& B
! N8 c8 m {7 ^% `- U7 ?1 D; P " X9 t" S3 T( p6 A
8.CSS带有阴影的双边框 2 y* j( x1 F0 T7 N
CSS代码:, i9 u+ g1 M8 s3 f2 E% h4 K
#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 O5 R: M" U X' W5 Z
3 U- ^1 w1 E$ W l' M+ u) R% N . a9 W. Y9 B( r* D' j- g& S
9.CSS多色边框 j' z( K$ d, @ g' S9 C
CSS代码:& A/ P# V# T& y4 M$ Y* V% M8 N% G
#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;
} 效果如下:
/ c! U% O! @4 Z& h; t7 b+ ]- L3 q