CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
' E: |: y+ \9 I% A 以下各特效用的HTML代码相同:
9 f# B# b9 a' w5 }, g<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 3 q9 j, w) J( _5 h1 z! k5 E, _& Z
1. CSS动画边框7 U4 z; y; Y7 S- s! D: N! u$ P
CSS代码:
- E7 w) _$ i( _/ t( S; t@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;
} 效果如下:( N2 f" b2 s4 W# g
+ B5 O( T# o, k5 l6 A
: O9 ^4 ?3 D% X; K* n; x0 ]2. CSS图像边框4 t/ N4 W2 l0 o3 d( N4 E8 m( O, Q
CSS代码:! \5 L2 ]& i* B
#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;
} 效果如下:' M+ d. k9 f+ g: q$ I0 n6 m
0 E; x+ G3 d4 X8 j5 F
. Y3 U( u# c# G! h% L3.CSS蛇式边框
# D0 K" D+ e/ _CSS代码:
# @6 G9 m0 S5 B, e; `#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. R+ H) u. ^* u: ^+ s
' q7 M& j! J5 H8 U. z
) c- E' ~+ f0 i3 c4.CSS阶梯样式边框3 @" t V$ b2 U: }$ u7 w
CSS代码:5 l. \! W6 D+ K) }6 p. D" j
#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
} 效果如下:
9 E( a. `8 Q! A3 ?
; O& [ A- i0 }* d- f" U- O
6 g( ?0 Q5 A! E4 _# i$ E; E5.CSS只有阴影边框' @9 ^6 r( m- j5 V; c/ H8 h6 U2 m
CSS代码:
( r- ]2 A. w. Z1 o! g' t#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:% o9 d+ ?5 v+ a8 j
( n7 t5 ~6 H+ U2 c# G( O- A
9 W& j& g& b& f) e# n; s6.CSS带阴影和轮廓的边框7 x3 E9 c8 a( `" x
CSS代码:
2 N5 @4 t8 I$ A N7 l6 n! a& k#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;
} 效果如下:
" k* C; k. B2 F9 |4 ^/ s4 J: a, s
1 M9 A) X: q' ?' Y4 n+ U% Z8 m* f7 ?
7.CSS少量阴影和轮廓的边框
- n3 v0 [+ e8 aCSS代码:
6 y0 K) J' E4 n7 @/ S. m6 C, E/ |#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;
} 效果如下:* T/ o( `: c- c
4 k/ p/ @1 u1 h: @
2 \6 N" K/ w Y- \( v- w
8.CSS带有阴影的双边框
" o) {! _8 V7 V7 B: qCSS代码:
* e1 i: l; ], D5 C: d( _3 x- L#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;
} 效果如下:) H" [4 o6 M% ~% L, }8 @
/ j4 w3 o3 d3 \% u. T8 S& L3 q+ ~4 H. W6 c! m( i" A8 n( z- m
9.CSS多色边框
. a1 u- M2 }# n- N; eCSS代码:
2 j8 f8 c. q% P- ^# ~. h( a#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;
} 效果如下:, b8 n' G& b7 L O
|