CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。$ f, o! s4 _, T' n4 W( J( o5 G) y* q
以下各特效用的HTML代码相同:
8 k$ |6 B6 l3 {<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> # D' L5 J5 b! E k/ V& U
1. CSS动画边框
% K g$ y V+ p" r$ B7 QCSS代码:
. u/ u/ F1 M; ?% f5 N@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;
} 效果如下:9 r g7 l. D& r1 a, |4 B% p" H$ J
4 \' G& {2 a5 p& i2 v2 J
6 b; z$ r* O4 d5 D( Z2. CSS图像边框! N0 u+ w' {# H! ?0 R q
CSS代码:
- y. t7 s" z4 ]8 ]. E#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;
} 效果如下:$ E( y2 }7 _$ o- }3 R7 Q( s$ u
4 k5 o! t0 n# B$ O: ~
{$ t n' ~& B; F. E' L D
3.CSS蛇式边框
" k# \& w: Y" y, ZCSS代码:4 Y4 V8 A3 F: {& D* \
#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;
} 效果如下:5 Z k3 N- Z: L6 N
* P- i4 i3 J2 }8 v, ^" c4 U
3 i+ N# e3 F$ u$ k7 L( y
4.CSS阶梯样式边框% E) p' W) `$ W/ m. c
CSS代码:
; n6 U0 \- Z' b9 s ?9 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
} 效果如下:
5 b1 R- L! D! g& c' f$ ^; J9 W
# B9 ^. a; E0 U" o, F9 x4 O
/ h0 |6 B9 t3 A: D5 @( d5.CSS只有阴影边框( l$ m( i# t' u9 G5 {# o
CSS代码:
/ C E: h' o# T, ~ J#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:3 T7 u3 V1 ?9 L
3 a a0 p- J; }2 u
# o7 Z7 ]! @6 y% ~& W9 _1 X6.CSS带阴影和轮廓的边框
8 L2 `9 C1 Q) M4 E9 C w' FCSS代码:5 [! c) i# d0 [
#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;
} 效果如下:
0 w8 E0 ?8 S+ M. B- K2 g' X
o) x: I1 z% L- a9 [
' |: x- }8 O: v' k3 f$ `! a" |7 U7.CSS少量阴影和轮廓的边框
& A3 a2 S- A8 @: TCSS代码:, r& D; O c" P# U6 J
#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;
} 效果如下:4 D- p0 _ A6 ^1 N+ S& B
& q% k8 r! O, o+ V: o3 q4 |
- W! J9 Z8 k" X" K7 x8.CSS带有阴影的双边框
5 {7 _. Y$ k4 O" P; h' }( MCSS代码:
0 }% R- @! w T. Q! P4 n; I7 c/ O, a#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;
} 效果如下:3 R7 _- z8 M# l* @; H, C: ~
0 b- E n/ W' u8 c6 O: N" p- i2 b( K
9.CSS多色边框
) e, C) [6 }4 J# y7 G% PCSS代码:, |8 w6 r+ u r& Z. L$ o
#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;
} 效果如下:
% b8 e$ L/ C# b
|