CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。- p( W& k5 Y" w0 C; r. }- [0 ~
以下各特效用的HTML代码相同:# I+ K9 z0 ?3 _0 ^$ S
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 2 e4 y- C, q4 ~! ?+ i# f
1. CSS动画边框 d. W. G. d9 }) p1 |
CSS代码:& D2 q9 R0 k" }! C: j. _( h! X; Z8 V
@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;
} 效果如下:
* _7 f# U& F u) z
# g6 ^0 G+ t, R1 r
0 X' t6 X2 ?9 S% L- J, t' q3 z2. CSS图像边框" q) U9 J$ S4 l: m3 L0 y/ V
CSS代码:/ k+ @) |+ r0 F) w$ g$ A; F
#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;
} 效果如下:
* E8 r# c& q2 N, O; W
& p9 f' ]% U9 @' [( v$ R
, o8 K! o3 {' j/ ]$ a z3 }3.CSS蛇式边框
4 R& i2 m+ |& d. \2 TCSS代码:1 }1 g% D+ g( C9 B6 r3 o6 x
#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;
} 效果如下:" U- e1 f! u7 r# h9 ?
* |8 J, W' J! z" h# G
! f% v- ?& S' c W7 r: T. n+ e4.CSS阶梯样式边框) O( U0 ~: L4 n2 S y1 T
CSS代码:% y% I# g3 f% S+ j4 b* i
#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
} 效果如下:7 r5 ^6 t% q5 }( c
! Y& j. \0 o) L1 S, W0 |
2 \/ ~9 ^$ s5 `' ?' ]
5.CSS只有阴影边框' w' _8 o9 r: X
CSS代码:" R# q7 T1 j; ?
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:( f: [; H6 f2 L" r9 {3 u6 G
4 }$ X- d$ L3 ]' Y$ P3 e2 y
# W7 \5 `% H: ?. l. _6.CSS带阴影和轮廓的边框
; V5 P' g6 I* e J# ^0 s. X" s: v( OCSS代码:/ ~5 }/ T* P% W# s
#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;
} 效果如下:. c: x- r0 Z4 j! [. _# ~
0 x3 P, N2 s1 k: _$ K
+ I1 B. g; m/ F( _! C- G: ], w7.CSS少量阴影和轮廓的边框
) |- ?) C$ d( H" J: S$ ~CSS代码:) T. S% N% o1 x
#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;
} 效果如下:4 e. |, @5 S6 ~, q( ?. p6 S1 p
4 K1 p- c; J/ N- ]) f. f
0 |) s" q, H; Z; n
8.CSS带有阴影的双边框
: P7 j; ~, ]# ~+ o1 |CSS代码:
4 i5 ~2 c0 A- Q0 N) N# v) o: U#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;
} 效果如下:
6 U+ w5 O& H2 V! @
0 _8 x8 Y; {2 m" i) y5 W
: T% k: X4 Q6 P4 G1 r# ?, J, u5 |9.CSS多色边框3 x! I: T. l8 b& V( T
CSS代码:
( v& c7 P0 f" i% D# {#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;
} 效果如下:% h$ U# x$ `( G
|