CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。; ~& M' F6 ~" H7 [
以下各特效用的HTML代码相同:, C; M5 p9 Y- T+ g0 [3 X$ ^$ X
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> ' k+ @! W. M0 j) ^0 T9 j' \
1. CSS动画边框4 Z' I/ f6 b. k; j" ~
CSS代码:
. R, i. ~8 Y& u+ X( n; T* L@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;
} 效果如下:
! n% g r1 E2 H u" u8 S. M0 t
8 a) M6 ~7 Z! v( e8 ~+ N3 ~
$ X: ?4 P3 v- c& }4 @$ P' v; h
2. CSS图像边框) ^5 ]1 Q5 V/ M: @
CSS代码:, k" w8 B [6 ~' b/ m
#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;
} 效果如下:3 k! f) x; @: D/ r9 _9 [
* n! @* P$ j% \0 s7 o
. k" ^: [2 N/ F( B5 W* n
3.CSS蛇式边框
7 F+ K4 q" w4 ^, b/ TCSS代码:2 h) V2 a, h0 Z8 Y1 t, V) ^
#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;
} 效果如下:' ]0 k( q; @, b1 ?" R6 W# H
9 O" A& e" T9 o) C
9 }8 W- N/ V& J5 m& G9 ~% s
4.CSS阶梯样式边框4 D5 K$ w4 ~/ Q' k
CSS代码:
+ L' m2 E" J2 B: S1 m7 X9 p, K#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
} 效果如下:
# H7 \8 X, i: [, H `" i
8 ^8 r( M% q3 v% g9 f% ~- c
$ {5 [) K/ B6 h+ }7 g5.CSS只有阴影边框
9 V6 c8 @* Q( J' nCSS代码:
( O- ?% @' S E, ]3 B; |+ n#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
7 G( c2 p X I+ p) g2 ~+ S
+ y1 L, M: ^0 J" \2 I* h" o& ^
R% s' Z" Y8 {% {) Z1 B2 T6.CSS带阴影和轮廓的边框3 m* j5 U% o3 w; I
CSS代码:$ C K! r! e$ l. \
#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;
} 效果如下:
- M4 _) F/ L6 p! V1 t
3 P) u3 @/ p6 L+ M7 r$ O" Q
# `8 [: T4 D0 L& b b7.CSS少量阴影和轮廓的边框: a, y* E9 G( E
CSS代码:
% Z: B- \$ e* J4 n#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;
} 效果如下:/ e' ]5 n. e: U* A7 ^9 o2 }) k
$ n, p t; ?3 m* c/ d2 E! ]
; U* h, d. o5 m- J8 T
8.CSS带有阴影的双边框
( s4 [) g1 ~$ G/ DCSS代码:
- c1 f( c( _* j- d- ~; }3 ~#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 f ?; x ~1 K
+ D" X9 s. B8 p) q0 e6 \
5 q, W3 ]' Q& e7 |; E9.CSS多色边框2 c( n6 @0 R" |+ U
CSS代码:
) o y% |# P5 b' {% G* o1 X#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;
} 效果如下:
4 S. l6 [/ k: i& H. [! K
|