CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。; R9 T: i0 d2 ~' R4 p# s
以下各特效用的HTML代码相同:
; v6 e% V4 |# Z" K! n2 C<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> ( }, F5 T* m' H* O$ T
1. CSS动画边框
9 l8 q" F! M; f9 c; VCSS代码:
0 L+ ?; s8 d* Y9 F! p; Q@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;
} 效果如下:
2 W2 y1 D$ W. S1 k1 B, r5 F
: W2 U# H, j/ J% E p6 u0 l& S2 u0 O
2. CSS图像边框
: B- O! T& C8 t. I/ L. W6 b/ pCSS代码:
' p$ ^- q# B( l#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;
} 效果如下:+ K8 J. R) P2 s: z) p
b9 t/ h/ b! g4 H$ \8 n3 }
+ M3 |- U" h; `% _. y, w/ \( A3.CSS蛇式边框
+ ~4 e7 x- [7 [) Y4 `6 J# pCSS代码:
$ U* ~5 e7 ]6 P( S) j' T. Q/ O: f#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;
} 效果如下:% v( J3 f3 {( E. d$ P: a7 w$ P J
$ g' B( N9 q- }( D' H1 y |8 T/ T# j9 d) _
4.CSS阶梯样式边框
) k# x5 C0 D- X/ Q5 e2 [CSS代码:/ h* s) F! [$ M2 p
#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
} 效果如下:
( Y1 T1 g+ i8 u6 X, C
3 L' j! w' N# f7 k) C4 I+ z" {
5 E2 O( `' M9 e6 B e0 k: Q5 n
5.CSS只有阴影边框
0 R0 W, G( ]6 r3 E' U, z/ h `- fCSS代码:8 {1 E2 ~3 {3 L0 [6 y* @
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
7 z. h) [8 C9 p0 q
" B- v6 Q; B0 h4 @
" \0 s, v+ Z; o5 m6.CSS带阴影和轮廓的边框
0 ~/ v) z+ O' ]' Z$ j GCSS代码:
, s) w& s: w' X! p6 ?- e#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;
} 效果如下:
" r" }$ [1 H8 a1 @. Z, [3 G
\- g7 Q( Y6 t6 Q6 r; h# Y6 P. Q
8 c* X1 l3 I! x: v6 Y7.CSS少量阴影和轮廓的边框
# Z' {/ c2 e) G. C8 d" @CSS代码:
& c) p7 ?( T) ?% }9 I2 v#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;
} 效果如下:2 q5 U, H. c* Y- R8 U
+ {. h( H& ]9 t' O4 c2 ~! J
$ N7 z% s" A2 r& C1 k+ F# X8.CSS带有阴影的双边框* Y; h* C3 o0 m3 m3 b, b }: _
CSS代码:# @/ O5 n) |1 k" B
#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;
} 效果如下: E/ }6 d" T0 n6 `
0 z; L4 z# Z* q3 a( w" Q" ?- X! j
5 t4 S% l$ r/ \. M9.CSS多色边框
7 }* p, U1 F( R; X, c" ?2 `% VCSS代码:
$ I. [ }6 I7 l, d7 t y! A! S#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 H+ m% |, v* ^- s9 Y
|