CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
3 d+ z% l2 A* c$ r- L6 E- N, |2 ]; f! r4 r 以下各特效用的HTML代码相同:, d0 K. p9 j3 V& t6 p7 M% ~) p
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 4 D# w0 w+ c# N7 O" {) b7 P( X8 g( W
1. CSS动画边框
/ e; ]7 [5 b j0 `) TCSS代码:
7 e. R8 Y5 A' c4 A3 N( n2 Y% A@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;
} 效果如下:
! l, R. k% r s8 p" O
3 P( e6 v% X5 n# G, _1 |% v
* k/ x4 E; |6 B6 f2. CSS图像边框: {4 F- P: F3 O% A( u% _2 Z; d
CSS代码:
/ B/ ?: O1 b; F k ~8 u+ W8 R#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;
} 效果如下: x5 j; E/ `; d2 d
X F) k- J8 f8 l( `+ k) D& R7 H
' e: g8 V2 Q2 u7 H7 N% ~
3.CSS蛇式边框
) z# u# s9 Q+ u9 P* }CSS代码:
" c8 h- {/ }" R9 x) r#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;
} 效果如下:
( b- d* m( Z7 f. s" U
% t6 b5 h! }! |$ E d+ q, y, A3 F+ B2 C& t/ s
4.CSS阶梯样式边框) x4 y4 F0 W! _6 j8 [$ X
CSS代码:& @* U! C: @8 N% s$ U
#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
} 效果如下:
: h) ]1 Y2 w' D3 V; j6 r
5 ?( }: E5 T' j" A1 ?8 p# ^& u% @3 Q
5.CSS只有阴影边框' `" [4 U% ~% c2 f3 _# ^; g
CSS代码:1 T: O& j8 ?* q
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
2 C8 E6 `, V6 N0 x% f2 U
" Z5 P7 O% B' |( C
0 u9 ?# g3 t& r5 Z Z6.CSS带阴影和轮廓的边框
. m a# f* e' W! {5 `+ ]& ~# ?CSS代码:
+ O- {6 ]0 `) z$ U5 `9 Z0 t+ q#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;
} 效果如下:. D' O1 ~6 y7 f9 X# K
2 b8 X; X# l+ i8 S5 }4 d% u8 A
) d5 X3 n2 J# C( [/ J
7.CSS少量阴影和轮廓的边框2 o# M( c2 [- i2 j! b2 ?
CSS代码:! h7 J3 s' p. m0 Q2 t# @; d6 }
#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;
} 效果如下:
( Y, j/ R5 \: C' d0 ~
% J2 a) s7 ^* T2 Y
1 \, g3 T: p. b8.CSS带有阴影的双边框$ `) X0 O) m: j! p
CSS代码:) S: ~# E+ [: w6 U9 G7 |
#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;
} 效果如下:; Z; B- b0 S* y
; V K( t6 V' q8 T+ i& t
( I- i- S9 i9 |- ?9.CSS多色边框' L1 }: h! r6 d* G" w
CSS代码:
- Z( b4 X# A' W1 Y. y4 v, ~9 r#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;
} 效果如下:6 D2 Y9 ?2 U5 s+ I B2 v' m
|