CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
: ]2 j9 K- G6 u p 以下各特效用的HTML代码相同:
. @' O+ N% o5 I<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
4 `1 A {. @0 R$ s! L2 O6 N1. CSS动画边框6 X+ A- j8 v9 ?( M
CSS代码:
5 r; N& t4 H: v3 W! `" y@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;
} 效果如下:& u+ ~9 h$ a, }. K3 R3 u
' `4 Q' T7 a8 o& Z
2 _- N2 H& g; Y8 `" \! [2. CSS图像边框
2 {# L# k1 z4 a6 M }CSS代码:) B! E6 L h: p& f K7 x
#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;
} 效果如下:
) C9 Q" R! D/ h: ~, t+ C4 _8 v. S' i
( D7 n# X8 ~7 b1 w# k+ l3 u
1 W- D9 h& U+ N3.CSS蛇式边框5 t0 {: j9 j# W4 }
CSS代码:
) b, `/ a C: H, y#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;
} 效果如下:" D5 f: |: B- E$ W9 r% O; @2 S) U) M
# V; a$ ^* _+ v( _$ U, D. w7 ~# H1 F& [- {3 ^
4.CSS阶梯样式边框' Q3 B9 N% S+ W# J% P
CSS代码:
' Y# p3 R6 u6 V( b% X7 |#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
} 效果如下:
" c& h3 ~/ D3 u0 v' _2 d
/ G9 y& v7 g/ k' _% Z
5 Y ^8 h; Z. O u! @' h+ `" }5.CSS只有阴影边框
, y, ]& p3 s- |! ]$ _CSS代码:+ O. V! g- D0 i1 B
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:- Q3 b; e# X0 c
) q% d! p F4 _6 K2 w
3 [* ^! U) R& d2 f" V
6.CSS带阴影和轮廓的边框) |7 h( O$ z3 P" [
CSS代码:6 v+ @% t2 @7 g; h. o3 |5 X" Y
#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. |% {; v. ^
7 O9 \, [+ c( r/ j2 Z$ r3 k: S7 t P8 K1 c: B- F5 O
7.CSS少量阴影和轮廓的边框" ^1 \7 C# N4 m7 g
CSS代码:8 l" ]$ }. W0 E, o2 S
#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;
} 效果如下:
; R* B( m: Y/ k3 i6 v! |
8 S! a5 e: j U6 C+ l
0 `6 S/ }, z9 e( i' u
8.CSS带有阴影的双边框
/ g* s& S( c/ r) H% s' jCSS代码:
( I6 q! X# ^2 ?$ c1 r% B3 w3 p#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;
} 效果如下:) T- ?9 Z5 r! i+ J0 p2 C& @
( w, ~- h9 S9 r/ n D
! ?( W: c6 v/ `9.CSS多色边框2 D6 Y T) |( G3 H: R
CSS代码:: {) {/ f6 ^/ [* {/ V- k
#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;
} 效果如下:
I5 q! S8 ?* r) ?- p8 e; C/ R
|