CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。( a8 E$ L0 O8 o! W- {
以下各特效用的HTML代码相同:2 l7 o4 y# f# I3 O2 W. k1 `6 Y5 M
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> : r" J, l5 ]! P* ~) H3 i' m
1. CSS动画边框
9 v0 L% l. F; v0 |3 wCSS代码:
8 J4 A( f- I9 S1 F5 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;
} 效果如下:8 W! l& [0 W; B! s
1 h8 {: w) ]! g) d) ~
z, h; o* w+ {% P) m; B2. CSS图像边框
1 V( [9 a4 B1 t# T8 h- CCSS代码:; ]$ o, h! c$ g3 G' J) t6 I8 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;
} 效果如下:) a& T0 C [" l/ r, V N
9 z$ K+ z. y3 }& o
/ [2 [8 X% ~: h* F- \9 n
3.CSS蛇式边框) @1 S4 _, Q9 c% t6 G) a
CSS代码:
) y+ u0 _7 J: g( Q" _8 a5 x) b#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;
} 效果如下:
j- J. H9 M; I, f" Z, D9 r. q
' T8 R3 T4 _. @; Z) ^% [$ f0 Y0 Y2 p1 o6 u& {) F
4.CSS阶梯样式边框/ x1 P5 X( P+ n8 x: K3 a9 P( ?
CSS代码:# G' r- ]% P6 q2 L# q9 {
#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
} 效果如下:
: x& X) L( f+ e7 g8 O# U
! F9 m; X1 h. A% g' R, d# K4 W! {3 F- V5 e. [
5.CSS只有阴影边框
& ^: O9 |% p% i3 b# G$ X; f' TCSS代码:/ O& S3 x' y$ |: k T
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
$ {+ _ n) Y- p1 i+ V
1 T, o; Y1 u; K! l Z+ Z
7 a* p. A* m& z$ C# q6 \* N
6.CSS带阴影和轮廓的边框& O4 j! u# J& R1 `+ V% U
CSS代码:; M5 x% Z. |6 e; }6 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;
} 效果如下:( `" M: P3 S8 N6 W9 u( G
4 [5 e1 Y1 I: N- }1 C
; T# ] o5 L3 ^- |8 J7.CSS少量阴影和轮廓的边框: {2 r$ X9 S/ A) O' t* j, p# a
CSS代码:# u p! o o: [
#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;
} 效果如下:% G: ~3 W( S8 B/ h& y, A; v$ U
# _) b) j" C& l$ ~( E
' C" f! u; F: |/ M
8.CSS带有阴影的双边框% q: D6 G P: X( }
CSS代码:' q# K" X/ E4 v* u" I1 W/ V6 F9 D
#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* Q6 E/ c# Q0 p# L
- T8 x3 q% i* {* g4 Y% k8 ]$ S1 r# Z
9.CSS多色边框- X! G6 ]" v& v- M6 R& r
CSS代码:
3 ~# i+ N S/ g) D 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;
} 效果如下:1 y3 c) P' J2 B1 t6 i/ n: Y$ C
|