CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。0 h6 R1 Y/ T0 ?. s: i) n8 u3 V7 j; s
以下各特效用的HTML代码相同:
k0 J2 s' v4 {0 `1 c" H* |6 M<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
6 j7 D. `8 M+ H1. CSS动画边框: z3 P+ T5 l) q. C6 e
CSS代码:7 X* X8 ~+ k0 Q% o& X. h
@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;
} 效果如下:, h3 F0 v9 a0 i2 u( T* F
4 O' o* ?' F; v9 ~' u% R$ H
: Q8 M( v) _7 j% K8 M! O, G( |2. CSS图像边框
. G- N! j# V( Z! zCSS代码:1 U7 d9 r4 H4 e0 M4 x5 m' X) 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;
} 效果如下:
3 ^) h6 C) E% `1 Q, Q
/ n6 o2 Z% r4 c, [) ?6 d8 \ T3 y) t9 U( ~5 [" T H4 \; _
3.CSS蛇式边框, J) A0 _7 u+ W' ?/ W! p
CSS代码:1 `7 j, ^! ^/ H3 y( m% x! W o4 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;
} 效果如下:5 b) b8 ]% z+ k6 T. C
4 H2 T- F `4 L7 P
1 n% @$ X; C3 T
4.CSS阶梯样式边框; x( K# j/ B) s
CSS代码:
8 h+ Z) t! `9 }#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
} 效果如下:! `2 g0 F+ K4 i$ I- X; E
. d7 Q' t/ C) q3 c! v0 B
3 i. ^9 _0 }6 h& Y" V
5.CSS只有阴影边框
+ X6 V9 Q* [8 sCSS代码:
6 E n2 b& w4 e e; p#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:4 V8 }2 ?! u" s+ _. i, m
& I, L( t9 z9 T) d
- J ?% A, Z9 t6 [6.CSS带阴影和轮廓的边框
6 Y$ N( F% I, h+ B; mCSS代码:
$ g' S- o/ X/ K' P#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;
} 效果如下:$ y2 ~, J, h6 h( x0 o: Q
) y5 {: `1 C3 l8 Q4 h& \
# ?% ^6 { x3 ]& h+ [' U3 w2 C; [7.CSS少量阴影和轮廓的边框
* x- I$ X8 w6 w4 T7 n( ICSS代码:
, _4 ^+ p @1 S' 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;
} 效果如下:
. e# {( W$ P$ X/ E6 a
9 t9 e4 H- B4 C9 v
& t! [# N. R+ N8.CSS带有阴影的双边框8 M2 J/ I4 y3 i7 S
CSS代码:* a" k2 y) B0 f9 U+ l( e
#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;
} 效果如下:
+ s7 u' I; T0 j* N
, v" U8 I% ?5 T: C7 U+ @ C! S" r
. I$ g5 Y3 V1 _# \% L9.CSS多色边框
7 K1 B2 p- x$ j0 u# z1 s3 M. wCSS代码:* L0 r# @% B9 w+ f+ |* ~8 c. 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;
} 效果如下:
9 O# T4 `1 w9 B8 v. _
|