CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。" q+ {1 q7 l; q3 @! q% M
以下各特效用的HTML代码相同:0 l: ]3 }7 Z* D# J
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 9 U/ _4 ?1 W' Y8 L M, P& @
1. CSS动画边框
* v a& O+ Y- |- C! ECSS代码:3 K: c$ f. f* E; _; }( o% V& 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;
} 效果如下:, l& K, C G+ K! v, s. x
" n {' h# X* z
, m. z. G3 Y" _" M5 `, Z2. CSS图像边框" }5 y; u e3 n1 d
CSS代码:* g6 r# x1 H7 D) {. K. g
#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;
} 效果如下:
# ^8 H' I) g1 V" K$ D
2 J2 y6 o; N* N- h9 n; o) C, @
8 i! _- `# r8 C/ Y' W! w3.CSS蛇式边框. y |+ R$ [' Q, A1 m5 E2 C# h! i6 `
CSS代码: L( i0 |& G% j3 i3 u
#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;
} 效果如下:; E3 _6 |$ h8 E; V6 n
& Y9 l2 P1 q+ A$ @4 a2 w0 }2 C6 u7 |* l' X7 I* Y
4.CSS阶梯样式边框
! t' l& W: J& v$ J! O/ }' aCSS代码:* N7 W& h7 Y) S0 v
#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
} 效果如下:' R3 t( E2 {; O* f T; H J
" V' A$ m% H: F$ ~0 G
, B1 J9 c0 z M8 q% J! _; m6 K/ W
5.CSS只有阴影边框 b, x1 o5 {& c. i% I5 S! Z
CSS代码:) Y5 M+ @5 U- Z, x7 q0 o6 ~
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:% U1 J) u- T6 y! W! O. |; R
2 @; `) u6 q- a7 r% @- O
( g. O: C, L" x6.CSS带阴影和轮廓的边框5 z! n) L+ f: j" W6 U
CSS代码:, H5 N' [2 f: U
#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;
} 效果如下:4 A0 Y( Q5 g! P1 A5 o% z
/ G7 C' q8 I) O! ^+ m; K5 `' T( c& S3 ?$ ]) p
7.CSS少量阴影和轮廓的边框
1 Y- K7 [5 o& Q+ NCSS代码:
7 |8 Z: t8 e: V% P, A" \#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;
} 效果如下:7 Q1 K- Z5 S! m$ B
) s+ N: q" r/ s+ H' n
/ \0 [" i. v4 v- J! k( @
8.CSS带有阴影的双边框) F, Q) E$ _; M' \" f3 u1 X
CSS代码:
' S8 u" S6 ]. f5 H% ]( ?2 r#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;
} 效果如下:* W; m8 b/ I1 i$ L: E% |4 a
y+ X4 A1 w+ }# I; Z8 \
/ X* A' A& ?0 w, Z+ U! v
9.CSS多色边框# y% n% n; e& c* M& r1 ]
CSS代码:' G6 X. J* G. ?" ^5 q1 _5 ?
#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;
} 效果如下:2 Q9 Z- g; K9 E7 v2 o' v# B
|