CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
! d" r% W8 R/ U1 m$ y* y/ Z! | 以下各特效用的HTML代码相同:
7 `! d; b$ b' H$ i. W, h- \<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> $ F3 @5 h' X9 w7 c
1. CSS动画边框
. w9 @' B7 g2 I3 mCSS代码:
8 E& f/ q) N& I@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;
} 效果如下:% a5 p+ M M6 r
; K/ h- r- a' c! z" s
m! P h' J" Q# p" r2. CSS图像边框1 b8 B( K* A5 f) R+ S8 R' @5 n
CSS代码:# }* F& V" C. o8 o( v$ Y: o
#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 Q; y* n z c0 ~5 D6 ^ n
6 L X9 Q# z. l( N
# [7 y/ x+ S3 _+ ~# j. K' P( ~* b3.CSS蛇式边框
5 t" m: {/ F6 C3 J( k7 [CSS代码:
5 B) Z7 t' c+ Z#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$ F% ~4 H4 U7 P% \1 ?
" F; l7 P! t) G: X& W1 s4 N
' W, @9 x' O& z4 }6 j* ?: {( x2 q. m; D
4.CSS阶梯样式边框6 T3 W4 q) u0 `* f, R
CSS代码:
# M* D3 R; V. b6 c, X$ i+ c#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
} 效果如下:
8 i- f' g: f1 j
. @1 X/ W' u7 n$ U1 k9 Y- ]' p- }
- X7 Z f( n. h* ^( |( t& L5.CSS只有阴影边框
- `, o7 l5 Z0 [. ]9 X4 a, x& QCSS代码:
% y; w% [* \* u! D3 t" l1 S6 K#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
. q) D/ N1 x. y M' {* y3 j
7 j! `; z: b+ ^( @
, M& D. e9 A2 z6.CSS带阴影和轮廓的边框* h( ]$ i9 g9 g' n
CSS代码:
Y6 D+ f3 u2 d) u4 v#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;
} 效果如下:
& k1 j5 j+ i" l, [% \5 r Q8 s$ [
! L) d/ \- N N% k
4 O4 O0 C; u+ ~* ~. Q9 U4 N0 \4 `- k9 n7.CSS少量阴影和轮廓的边框8 o" k. ^% c* [4 A; Z( l
CSS代码:. i( I. [; h1 R f) z. M
#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;
} 效果如下:
/ T4 a" E7 x( R, p9 T3 z
- L3 N' d! t) g9 G( r
, ~8 Z/ o' w2 _( S( Y8.CSS带有阴影的双边框 T2 q# x7 b3 j3 X, h/ Q' a
CSS代码:
3 k+ C* ?: z; {#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;
} 效果如下:
: w* v8 p- A3 r4 N4 D; ]
* ^( f/ \& b) h6 R; O
5 k, v) f* D( a. b9.CSS多色边框+ Y) ~7 s5 P+ Y- V
CSS代码:
- w- h+ o4 `: `#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;
} 效果如下:. j \. R, O' z$ g! n: D
|