CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。% f' O; W9 y3 [& ~
以下各特效用的HTML代码相同:- o: J" G( f% ]5 E4 D
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
: S$ _; z9 r& j1 y& Z1 D1. CSS动画边框
" k9 b9 K6 o4 E! P2 @# bCSS代码:: I, T: {7 p0 F- y9 Y" P
@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 z$ `' T0 t$ Q& J7 P# [& t$ W
" c) V' y9 x: L
* M _* S- d2 Y' u+ w2. CSS图像边框/ v: x3 E# _. h; h! ] f/ N, F( q
CSS代码:% `+ A+ ]. @8 R7 G( \$ P* j
#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;
} 效果如下:/ z- g8 s& m2 [+ m
' T- b" J/ v% P5 c$ ~
( z( M* b' U9 Z2 u$ ~& c3.CSS蛇式边框
" `7 N& S/ p" }* a* nCSS代码:9 Q+ h6 I, K+ Z& `2 S
#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 w' H; N) e
- m" f4 i* \1 X& p& R3 F7 q2 I5 Y! J1 c$ T: x' a
4.CSS阶梯样式边框' o% u. i7 e+ i H8 _1 F
CSS代码:
0 \" m% a/ A# ?% m7 s#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 Z m2 c( o9 A) _& K8 ?
1 x! ?7 p- \! t4 [6 D( T0 A0 G4 L3 n1 ?1 B7 h
5.CSS只有阴影边框+ Y- H# e/ b" _$ K7 J; i
CSS代码:
; S2 [# b7 X9 \. p. M#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:" B3 P* Z2 @* E- L( y4 v
7 L/ v Y. \1 N
3 s8 J, M% Z* i6.CSS带阴影和轮廓的边框$ H+ b/ }1 F) i. G, r; z
CSS代码:% [8 h2 [% R; T/ @9 B. ?
#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;
} 效果如下:
: u' ]1 p0 g# A& j0 T& x0 R
# b* ^3 z( o4 A, Z* n0 s3 d% U. B' T1 X5 h
7.CSS少量阴影和轮廓的边框9 w9 x; n1 w/ y& z/ v
CSS代码:
) K* {! u7 {( g$ T#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;
} 效果如下:
* }' j: `0 I' [3 c' p: S
0 J7 B, f" D$ }3 S& r7 p! Y5 e( Q( R i1 V+ C
8.CSS带有阴影的双边框0 Q) R; A- e5 V/ p: I! g5 _* q( F
CSS代码:
8 [% J* F7 p4 p C$ f- T6 x#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;
} 效果如下:" X) R1 p: m) u, {/ v! V' W) B
6 _. T4 L1 }4 L1 N% K4 S1 Y: I* U( x
9.CSS多色边框
1 y' o' u, P3 \2 }6 x1 Z5 x( ~( LCSS代码:$ ~# D3 F9 }; ^2 B- M+ `! V
#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;
} 效果如下:
+ s* X# R5 v# Z2 Q: P4 y
|