CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。4 s" y5 ^- a% H: \' L. X8 w$ Y
以下各特效用的HTML代码相同:
% N% I, H6 ^0 v5 F4 H <div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
8 E# ~: n" C) `6 ^/ S# i) X 1. CSS动画边框
8 P1 @0 B. A3 m CSS代码:
/ s3 N6 d, y' t& S! m @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 E8 Q M6 u G g9 @; D" Y
3 w' O0 G6 o$ T* s* g
% t! E: s5 O% p/ i% j1 n 2. CSS图像边框 : z$ k' w& }9 o! f
CSS代码:8 x6 a4 x7 {8 D% m
#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;
} 效果如下:
R1 i& u `1 n8 W9 }5 y
# ]+ \) W0 J& R1 q: r: A
# T- F8 @% r/ J$ K, Q) h) ?
3.CSS蛇式边框
( }7 S8 r; j4 a6 f$ Z CSS代码:* B% d8 a4 L6 {% V
#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;
} 效果如下:( _4 A$ J! [, C4 ? X( b
3 D5 u- w4 _: i! a
- v: V K9 k2 Y0 |! J B2 i* D 4.CSS阶梯样式边框 U8 e5 Y6 |9 L7 S" w n7 M+ t% _
CSS代码:
' D# Z/ l3 J* O1 Q1 |) g4 D #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
} 效果如下:
& B9 G/ T' P/ J$ u# k
2 J( z0 s& V; @# R0 Y
8 z/ `* U/ R8 _6 z1 D/ t1 Q7 p
5.CSS只有阴影边框 r+ C& Z2 O9 `3 O4 `
CSS代码:
" ]4 Q8 |3 A6 K8 u# B. {* L #box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:6 v$ u6 K# h, N; z* y4 W
b$ i' H- |$ `, Y
" h" s8 B& p4 g+ V; Q 6.CSS带阴影和轮廓的边框 ' ~/ _+ |0 q1 v2 H
CSS代码:2 S: s9 p3 B0 `9 ?) `+ ~
#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;
} 效果如下:6 p% E- k7 V5 |/ {3 w6 }& g8 z
+ A1 s7 V/ V: y+ Y; ?
9 G; i! r3 I) A7 \
7.CSS少量阴影和轮廓的边框 . a$ m6 j( E1 d: t$ W+ }% S# |
CSS代码:
! E6 Q7 E4 O3 A/ Q #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;
} 效果如下:: ~5 w/ M0 O9 _/ f; e' K3 n' t5 X* h
9 @* G2 v' @- C m0 B( W7 G9 Y, P) W* `
0 z# s0 f+ r- o0 S* ^9 j 8.CSS带有阴影的双边框 4 o: w* Y; f& ^4 P1 ]
CSS代码:
. }+ ]6 ?4 m9 i #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;
} 效果如下:
" k4 [9 V9 @' w' \4 t
u1 F- M8 H i1 c) p
, ?; n4 u4 f% G* U" A! X6 E 9.CSS多色边框 / B/ @" J/ I8 O4 a( B, c) O V
CSS代码:
" s( F5 {* Y& h: l. v. ^- j" [) M #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;
} 效果如下:
! L% K! x# s% g/ T6 f