CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。2 b- I% N$ ~; G1 u) E& Y3 i2 d. c
以下各特效用的HTML代码相同:; n- W0 j) y# G7 f t
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 0 g! D) w3 z7 p
1. CSS动画边框! m/ ?; O. R' X( K/ O
CSS代码:, b# r% H6 S$ W( Q- n* M9 b
@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 B4 R+ Q7 {& |% g; K, `4 H, }
( Y# F! P4 U( v% x4 a
0 F% Q8 G7 v; _/ c9 y2. CSS图像边框 Q# |+ X$ R# _) i$ ~6 U2 x
CSS代码:
- @* S- o1 g6 R2 k2 }$ p#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;
} 效果如下:: o3 x+ f! U) @
' A9 b4 d: C2 O W4 T( q& y) z2 l+ v1 L# F0 V$ J) ~
3.CSS蛇式边框5 I. l% v- V* L% g: ?/ E) x+ G; j" A
CSS代码:& R/ O5 { R3 p& e! k4 }
#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 Z+ u: l a' \1 w" o
1 a: P6 ^& o, f% V V1 _6 |
6 s- U5 A/ I3 v" e4.CSS阶梯样式边框
q9 B5 T0 ^3 GCSS代码:( B& H/ v7 f6 l6 b
#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
} 效果如下:, y3 G1 ]- C/ a3 P, x: {
! I% w8 i' H# @
1 ?; c' C& U; _
5.CSS只有阴影边框
+ U" g2 }6 ]0 o/ s4 u. rCSS代码:
3 R, d$ ?# x$ `7 E" H#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:. Y/ b6 h# H4 r0 Q' O( _4 ?
& U% x8 p5 n$ e- @2 K% O
/ T d" ]# F7 h9 ?/ @0 D* {
6.CSS带阴影和轮廓的边框6 J3 o7 i9 q: t, [& a3 D$ K
CSS代码:
+ z) f; R$ _% A! {4 w#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;
} 效果如下:* D7 ]* P! V0 t6 J t7 Y
/ I0 M9 N9 @1 p. q& ]
, x8 d0 i& s* a2 `# I5 Q/ l! Z7.CSS少量阴影和轮廓的边框' N$ P" n2 ?# [% z
CSS代码:
& y# M( S/ m# R+ v" B2 b#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;
} 效果如下:
( ?6 ]0 g6 K, O! N1 h
- S% v0 G V/ @' A, X; [
w/ ?9 k: q! r* P9 l: j8.CSS带有阴影的双边框% N) S9 ?) J1 ^
CSS代码:
* x5 c: c/ p* i9 t2 M#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;
} 效果如下:
' a. t0 w5 z+ Y5 N( @
( V! P# X8 f. V, X: L$ U& n& q" {! l
/ b X1 Y; E P9.CSS多色边框2 R, Y' s& w2 l
CSS代码:4 i1 t4 u* ]# x# r7 U' |$ g9 E
#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;
} 效果如下:
9 y' P: ~ x% Y- J: z0 ]
|