CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
" ^: `9 K( b- {! z+ ` 以下各特效用的HTML代码相同:3 N7 {6 @' Y( w) x6 W* n! U
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> @0 U* X" y/ Y, _
1. CSS动画边框
4 x" J* M/ _4 I: d4 D CSS代码:
4 }) V& ^5 h0 Q: ~" p6 D% ?2 p @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;
} 效果如下:/ D+ T2 f5 g' a( Z8 y4 z9 |+ J: m
. S/ u, H6 z2 Y/ n 2 c! K# U* G' P8 p
2. CSS图像边框
$ |8 x) T9 y9 |4 R6 E- y! V" [ CSS代码:5 l, L8 [7 @: K6 I2 x
#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;
} 效果如下:
7 S% U+ l. I/ m- c& C: y
6 ^$ z( Q$ L! H6 g
* ` m2 S m7 Y) l, U9 L) ^
3.CSS蛇式边框
3 |2 q: f, }2 S' |" H CSS代码:
# o9 S3 a9 F9 I5 d, {7 | #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;
} 效果如下:1 o B4 x9 [5 u! n+ _% R j; o
9 M7 M2 @/ J9 n# X3 t/ z
6 f* o% @9 `& q4 e5 w1 w7 K
4.CSS阶梯样式边框 ; a7 t+ X+ V2 `6 {$ p9 ]
CSS代码:
1 L3 m" r. I; E, T5 T #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
} 效果如下:% I2 C3 A7 y% h" I7 o7 a% f
- l5 b; m5 ~( S" `1 J9 x5 X7 Y
% t8 H2 @2 `: u @# }$ K4 g" S+ k 5.CSS只有阴影边框
! A' f" ?$ E1 j: y9 W: f+ K CSS代码:7 r8 U- }& r/ 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;
} 效果如下:6 k) {# F- }1 o
# M! c& h8 z8 l( S
1 q$ y. o/ q! U; O1 k( ]# ~ 6.CSS带阴影和轮廓的边框 + C7 F/ P$ L5 F: s, ^3 R" A/ x
CSS代码:# r& A2 G" e: H7 p
#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;
} 效果如下:- ^1 E; ]: D) @$ S
6 p; V3 D' i4 i$ g# @* x6 u2 Q
! j# p! ~9 P \. a. c% B7 g
7.CSS少量阴影和轮廓的边框 % r, f. w p1 F. q. Y: Q9 _
CSS代码:
/ e$ r% ?5 k6 ?; o, t) x #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;
} 效果如下:
3 P9 F. z5 G2 v1 T
2 v$ c+ j: s% ]0 Q! B) P, F6 M. l
3 @' \8 z: ?' p$ x$ u 8.CSS带有阴影的双边框
( c1 b# D5 r$ |* D/ }: B CSS代码:
! d$ e3 X( i) d #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;
} 效果如下:
6 t( t2 A% W0 Z: f
d ^4 V& D+ a & N: a; R" D0 \
9.CSS多色边框
2 F) {( [% l* V$ Q! }+ t) \3 q CSS代码:9 R3 J$ \1 t6 z8 ^" V6 G
#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;
} 效果如下:
% e7 L- k, I& Y. B( x" g! l7 V