CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。0 ~5 ^9 q: h. V U6 ~
以下各特效用的HTML代码相同:# K1 O* S- R, p$ I; \
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 5 A! b: z. x! T1 w$ {
1. CSS动画边框
* w. n/ g: ^; O0 kCSS代码:
! u. `$ k* g, @. C@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;
} 效果如下:, \4 c: ]! Y7 @. {; |. M" J
& a; T, t- ^+ {; m! k. p: m/ R K& l
+ h0 g! T9 ^/ a, j7 o2. CSS图像边框# H! I6 q6 M m7 v/ x1 J
CSS代码:* I/ P, e/ [; \2 D2 p* ~
#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;
} 效果如下:6 H+ m; C" ]& g. p; Z
* Z/ r! B' }2 e4 a; U
* L, f, K& y% b8 | t: V p7 m; ?3.CSS蛇式边框& X3 G+ ?8 E/ w
CSS代码:
7 Z; T3 j; F: T8 p7 b: c" o0 U6 X#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;
} 效果如下:
; G2 n) m; T7 m& H
% n2 N3 w( z0 n4 D
* D! H6 c) V( R. t3 m4.CSS阶梯样式边框
& g) \/ }( `6 aCSS代码:
! m6 _" S7 M8 ~7 h- s- x0 X#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
} 效果如下:, I: X5 J0 H+ g
% m7 E$ K. X% B. \& o- f
) R# k, b! @! y0 I& p; e, Z5.CSS只有阴影边框
; X9 Z; j8 z \CSS代码:
0 f& q. q! r: |#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:5 W, Y0 m! d f$ g
( ?: u j" I# S4 _. q: a
% M7 w% w! n( Q
6.CSS带阴影和轮廓的边框% }) f# L( u7 {# _% f' U; P A
CSS代码:
3 h" f* M0 Y( }( ?2 M; B' L; C#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;
} 效果如下:9 Q6 ?2 i9 e" P8 y
$ u% @( |. b& ~) P* U8 T( L. P9 ]7 R* Z8 f# k: q2 G* X, H! ?) ?
7.CSS少量阴影和轮廓的边框! s; ]7 C2 X+ ^! R
CSS代码:6 [; [" w# m5 O1 q; M; 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;
} 效果如下:
/ D0 j7 N$ p0 S+ q
4 t n4 T/ r( b+ I$ @5 y' u
( s, ~8 k2 n! p5 j3 T8.CSS带有阴影的双边框
, G) `" {, X/ M) ^" d8 ]CSS代码:
# X3 _4 \6 H$ \; l( E+ z0 [#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 g0 [9 o. b2 u
: n; S9 S; L) w
' {4 ], c5 Q* @, Y9 `* W2 U9.CSS多色边框
. Z( j' B1 v8 y% c8 C5 w, [0 DCSS代码:
2 G8 U1 [! n2 [#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;
} 效果如下:
3 Q( { t {3 b( F* |' X
|