CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。. K0 ]: _6 O: q, p) @5 h
以下各特效用的HTML代码相同:
, w' a. W9 }) D. B<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
5 H4 l" ]1 U! H v' c" P1. CSS动画边框
9 c8 L# N2 X! J; v/ `1 A3 rCSS代码:
0 d, X" X K7 T! m; F; P: J; T@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;
} 效果如下:
# R: u$ y- U+ Q9 d+ k* B8 ?
, o1 u1 L9 a# T9 B4 y2 ]1 Y5 C, m
: w* H; t. @& F
2. CSS图像边框: c# G$ z& e- r
CSS代码:2 }- }) Q4 J; G5 K0 s% D1 b& I' q
#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;
} 效果如下:1 Z. w- s5 m* P; c/ i0 P' C$ I" Z
% Y, R5 g& o1 b/ l
9 ?/ A- H. T3 X3.CSS蛇式边框+ {0 I! u0 Z+ X9 w: R7 C0 E* t" U( C. j
CSS代码:* [! M# N9 y6 @: X9 v4 ^2 i
#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;
} 效果如下:
4 x! O' A. O- K c1 }0 s
1 Y' D& z; P7 E/ Z+ w# V
1 W+ q! Z; M' C0 w. R. Q; `
4.CSS阶梯样式边框
& l3 N$ y9 w3 w8 k5 ECSS代码:
2 G$ V% S! [6 P9 K* q, \, N#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
} 效果如下:; {- b2 p! V% c7 R8 [
4 U9 C# q5 k3 g; N. D9 A" h
* f; N) P" O! v# }! ^6 k. n& n5.CSS只有阴影边框
8 g/ W- E3 Z& ?( eCSS代码:/ w8 f3 f# X( Y4 I/ O
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
) y5 W2 C; W5 ~0 v1 J% S) s
6 _) K! u) p$ v/ x$ D" e( M8 c5 C0 m" W6 i' J- W
6.CSS带阴影和轮廓的边框1 e; L" C8 u/ x
CSS代码:+ Y6 l; U9 `; Y* l+ p2 y
#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;
} 效果如下:
( b$ u1 [% n$ o1 N0 d7 I* w9 f
6 L9 b+ |- C% h
4 R4 }+ |1 H) L& g7 p; m7.CSS少量阴影和轮廓的边框0 @% i+ P* ~# \; F& m
CSS代码:
( k/ t( j& W9 { D0 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;
} 效果如下:2 P6 r2 W" s, V- X! s/ I6 a
+ B# Y& I2 O% O& X- E5 ?% |% t! J% z1 ^
8.CSS带有阴影的双边框8 J- Y: D% v# d m5 t. D
CSS代码:
) H/ H ?, f. B: X) {$ u$ q8 F#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;
} 效果如下:5 H+ h* ~6 n! Q5 N5 R! b9 L
! y, J1 m7 Y$ B: {6 r) {0 A. t( h! m7 Q6 G8 m) m
9.CSS多色边框8 z3 S; s$ V6 ~8 o7 p& b* z% y
CSS代码:' U) @+ o5 }+ @9 Y
#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;
} 效果如下:! M7 w9 ]9 c. M1 b
|