CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
r; ^5 u) @$ t7 o+ h 以下各特效用的HTML代码相同:
+ k Y3 x+ E" d/ T8 W8 c# D<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> h; w8 J9 [1 A) I9 N
1. CSS动画边框4 ~) ?+ z" Z& ^% E
CSS代码:
4 Z4 z ~3 H! O( i, C* q; w- x@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;
} 效果如下:8 D* q( x% ~# j
7 `: _6 x- E! P3 K" G; R
: u+ m- Q6 F1 L) I: E, j8 w- q, y0 M2. CSS图像边框/ R7 u# |. T8 m$ f+ a
CSS代码:
3 A8 V6 H' x$ ]+ z1 B! r( 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;
} 效果如下:1 q) g$ l G( o# E8 J* B# b" q; b
7 w( a( l* z" x" ^0 P7 F& |1 l
z$ w+ @+ ?1 e3.CSS蛇式边框$ \, B7 F/ C8 q: H* |) q
CSS代码:
: c- j0 r8 ~9 o1 p9 K1 I#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;
} 效果如下:
. I. l% @. A) M" f9 b$ e- G% t3 {
- X( s7 Z" T2 O2 Q# Q3 K
% S8 v+ d4 N$ t" @1 U4 S9 J4.CSS阶梯样式边框3 j8 c8 z1 X$ _6 h6 j" {2 |
CSS代码:0 F6 m. l8 Z& c; L4 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
} 效果如下:
/ q, H0 n' t1 ]( v1 U9 ]' k5 X8 |
y' g' W! l4 W# E9 ?& P1 H% N' q: b$ |1 c
5.CSS只有阴影边框1 [0 I: J/ w7 s3 o ^, }
CSS代码:3 |! O+ L- p3 U
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
' U9 [0 ]6 O$ [, X. y/ p
% ]* U" ]( i/ q1 f/ M
0 z/ C; x# G/ z9 f+ M- ~ z+ w
6.CSS带阴影和轮廓的边框
+ y8 v# t. o* ~* }+ ]( ~CSS代码:
4 s( N0 Q) p$ u( `#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;
} 效果如下:: P# L5 `) N' ?' P2 A1 ]; D @# _- o
7 a: k: z; H' ~. ?6 m
, k& B, m9 s8 P
7.CSS少量阴影和轮廓的边框" v. Z( Z; l% {, K/ H- p/ g( W
CSS代码:
0 h7 Y6 w" `# U#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;
} 效果如下:+ d" T* q$ D9 R; D6 M4 L$ z8 f- ?, u u
8 {3 k3 ^0 }8 q3 q2 `% M! y
( w/ h/ M8 m0 s$ v- p8.CSS带有阴影的双边框
& ^. R: D+ b: _$ u# l: z5 q- ?CSS代码:' g, r% O& M- j% ?0 i- \0 i" h+ i
#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;
} 效果如下:
" J+ b* M4 W1 s1 Y( u& Z
9 H$ ]0 j4 N: T2 |- P/ g
/ ^7 ]$ i4 W8 s( v e* ^$ J
9.CSS多色边框/ A" g& P" W6 }/ F
CSS代码:
. |/ C: x3 F- ?$ [#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;
} 效果如下:8 ?6 }- }: @6 n6 B
|