CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
l7 w6 I! r0 [; Y& Y 以下各特效用的HTML代码相同:
9 o: Q' Z- Z7 G. }% J' `<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> n" }2 I6 x" L* a7 C5 G) X7 `
1. CSS动画边框
7 y1 e$ d& y) ~) MCSS代码:
. j# a) }7 r# A6 j/ R5 |2 K@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;
} 效果如下:1 S: f. [( F& @9 g9 F' D
* B! Y2 w$ F: F) D: c+ y
; E) L& z q* Y B5 o
2. CSS图像边框
6 P; m; R+ l j. ^CSS代码:
) w! v4 C2 `* v) I#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;
} 效果如下:1 P! u+ V0 e- _& T$ j4 \
' Z8 _( ~7 l- r, X0 ~; |2 s4 a
, A6 G, p+ h( g) e% X; p* E3.CSS蛇式边框/ a- v( y: T4 y6 x8 E
CSS代码:6 Z/ g- S/ M2 [8 I) Z: i0 ?/ s
#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;
} 效果如下:/ c* |0 Q0 u2 T
* J! U1 k C5 y) d [- C6 |1 x" i* z
6 N1 T) e% F! g4 d2 M* U4.CSS阶梯样式边框5 k9 k/ N# x3 w( G* b& Y$ O* L% A
CSS代码:
, f& Z- o2 p9 t- { q2 R+ `#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
} 效果如下:" E2 j0 V6 G+ P# b6 D
' r6 U8 L J F' j% O- H
- B1 V$ s9 i1 X! X4 _; r; R# ~5 ^5.CSS只有阴影边框7 S/ B& F6 X) g) w5 L
CSS代码:. j+ D: ]5 Q3 Q* W( A* \/ O
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
# v T: a, V! o; G6 w x
) U) R/ x! y: u# e: Q) I/ z
+ |; H" r' I1 [2 a$ V O6.CSS带阴影和轮廓的边框% g# Q X2 \: R" y
CSS代码:+ A b9 I e& O, j( N# D5 H" k
#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) u% w+ Q' ?* w; j; Z
5 m$ r; d/ e: z" R
/ Q; S8 M5 W; I- r" H# x: y" C9 l7.CSS少量阴影和轮廓的边框# {2 F* K, C: q* R
CSS代码:
. n* X. P% z' b$ v6 U0 D#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;
} 效果如下:+ K" Y8 Q" G m: w$ w
. C* p2 S1 y/ p; s, z% }6 Z2 e4 Z" t( B4 S4 p
8.CSS带有阴影的双边框
. c) c0 z5 O$ K0 o6 h5 f0 _& PCSS代码:, d* _+ C1 p9 G. t; J3 \
#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;
} 效果如下:2 ~) _/ B; K' Z
5 S. l v0 T2 y
( I" G+ v: ?- E: F3 N
9.CSS多色边框
4 L! f; H* L# I5 B! L4 k2 Z% XCSS代码:. z! ?2 Z0 P8 ^3 e8 D6 S/ ^1 d# J
#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 t4 O4 ~- v+ O$ F& Y5 n
|