CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。! E, Y/ Z6 K/ }' C V
以下各特效用的HTML代码相同:
* Z& \* _! N: u5 ~; q- V' ~" I <div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
5 C, P' r( g9 t8 c 1. CSS动画边框
) |- J" @/ u3 b7 r7 P7 Q CSS代码:5 [' e6 w% I- P$ Q/ A) [$ z
@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;
} 效果如下:# b+ @; Y- P8 Q5 T! D3 [
2 s. i' |: r% x$ Q- w+ l
7 D* {5 V) I# b5 T9 D
2. CSS图像边框
% J t1 q' z3 B6 T" A$ ?8 c CSS代码:
. M3 j- ~1 e0 ~) B- {+ I1 R- Y# I #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;
} 效果如下: [- I% T* R. s0 ]" p: t: }9 _: R
' J' Z1 g1 |. v, ] O2 Y* A% _ ; V5 H! \$ Z& x, {* X
3.CSS蛇式边框
$ O c/ b0 n1 c3 m; a. g8 i CSS代码:/ x' p% h5 U. D6 n9 ~
#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 g) C1 D3 L: e
( o7 t5 R. W# a; g0 j: J+ _ # l5 ?& h9 \# W
4.CSS阶梯样式边框 6 A4 z; {# i& D F. }# I
CSS代码:
7 e% } S# K3 `; \3 @' L$ 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
} 效果如下:! t4 J' h, M. O+ r8 E
7 w, d$ P6 ?; f 6 d0 S X7 d& W2 y- r2 k5 `
5.CSS只有阴影边框 7 q1 j' t1 P, m& G
CSS代码:. \6 }2 ^& m; S# K
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
+ i, Y" U) Q0 ]/ J7 Z: a% w5 \: i
7 d- W9 t j; C% N6 C+ \% ~# l
6 j" ]" a+ H8 j' K, W9 E
6.CSS带阴影和轮廓的边框
1 k' R1 R S' s9 j CSS代码:5 W% T7 E Y1 @. z0 J0 V& e
#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;
} 效果如下:
8 t; D4 h( w& z5 y5 `7 l
: Y: j6 w* ]% Q
/ F+ R# k5 p7 z& k0 s( L 7.CSS少量阴影和轮廓的边框 * S0 C% K% r. J- J0 @
CSS代码:& w2 e @) |2 x) C- u
#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;
} 效果如下:: S5 e7 ^5 K6 I# \/ s
& @% {2 J, @( P2 u* c7 s$ r
+ ^2 j: ]- G+ s6 {) x6 w3 R 8.CSS带有阴影的双边框 : q1 l$ c9 a W# S0 b" V+ @# N) L
CSS代码:
( b' i2 R2 a8 z9 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;
} 效果如下:
4 X t Q1 w- A6 |- ~- e5 t, _7 c
% ^& [, z9 L$ A
$ V- }; W5 D; X1 C# D' e 9.CSS多色边框 ' f5 c! r2 Z6 Y/ p' o
CSS代码:: j) D( ]0 d! S
#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;
} 效果如下:
b, E S G+ t. ?# ^