CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。! W& d6 \$ A2 N% w
以下各特效用的HTML代码相同:
8 I' h7 R! C1 I<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
0 v6 f, \" w/ ^( s1. CSS动画边框
; M5 N# T+ n3 R: a: h; y: e+ uCSS代码:: G* ^3 {, j* r( G2 {$ y2 s @) l( j
@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% t {% @0 T
+ ]3 F J, e; S) o4 y2 O4 n2 J z7 t3 g% X! L) C, t4 m7 z
2. CSS图像边框
8 c3 T$ {% t" Z U$ J4 [CSS代码:
. |8 G0 h4 c2 l#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;
} 效果如下:# k" }1 T1 ]" |+ m% l, C8 _
, p% L0 I; ^8 y8 S0 u1 g, x) O
6 E0 d; @3 C" ~3.CSS蛇式边框0 }( J# d h+ ^6 K! _$ j; {( ?8 R
CSS代码:5 u3 F5 w) Y1 O: F8 K! n' B
#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;
} 效果如下:
( G/ M; ^9 Z; M/ Z2 U: l
8 i0 u2 k% m1 ~
- U, Z; i( m# }, H7 I7 l% h4.CSS阶梯样式边框 k! \5 N" v7 r
CSS代码:% W9 Z9 c r9 J7 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
} 效果如下:( Q; \% \, |9 Z& `5 v0 O7 {' I
4 C4 u- W0 t# J# ^1 J+ |1 t1 E& W* c) W# e3 s* ^7 Y5 U
5.CSS只有阴影边框
) B$ q2 B, o1 [! U$ SCSS代码:: c; g6 ~- D6 c: S
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:; f* H1 g, W# H: d- F: Z
; L. O" p2 @1 ^" A8 r
2 a: z; r. H7 a0 O( V' X7 ]$ t6.CSS带阴影和轮廓的边框8 Q- F3 M. p5 J
CSS代码:
5 R6 t0 Z' Y; \: W#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;
} 效果如下:4 l6 n1 i0 o4 \
* k- \" \' _* i! a& ]
N& @* T: Z) U/ ]7.CSS少量阴影和轮廓的边框5 e V- ?4 W# C! e O) p
CSS代码:0 m6 T X) _% t2 N5 y
#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;
} 效果如下:
$ q! H; {9 V9 s1 S
( x7 T1 B, ]/ K g' y* e3 b; l9 M; d: N, p. W; D$ l
8.CSS带有阴影的双边框
+ j ^0 e. d8 g; W* r# H9 xCSS代码:
! |4 u$ U2 s* u& s# S( m#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;
} 效果如下:
" O9 s/ [) U: K* N
" [& v2 X7 C# J" o7 Z. x- e! Q. v2 u* r P
9.CSS多色边框7 Q8 p& M7 C+ ^0 T% p6 z
CSS代码:
9 l9 C* N1 L9 Q#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;
} 效果如下:" k6 `( s- ?0 @" I
|