CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
# P0 t2 v: h; n; T' p; _7 c" r 以下各特效用的HTML代码相同:
1 N( k; S1 r4 Y8 m0 g; }% r5 W<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
4 o3 z, G8 W: @+ X# }1. CSS动画边框+ @0 z( g8 N6 i4 E
CSS代码:
( D4 c/ _5 o% @6 [/ D# z@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;
} 效果如下:
( A+ @7 t* H3 a) B- Q) N
7 ] W& K( e' T% F8 B4 s% [) s- I3 T& p4 F5 X1 ]9 L
2. CSS图像边框
' R% g7 U) L. Q$ S- o- Q3 ?7 O# e3 J, |CSS代码:
# J0 A! o1 F3 Z" l: F( [8 F7 ^#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;
} 效果如下:0 F6 @3 d& K8 j. y! g; ], D4 y
3 R2 T; a: e. Q/ q; T
, [( K" O! z7 l9 {
3.CSS蛇式边框 m" H& F5 S; ^1 s7 \2 J* `& h+ J" j* Z
CSS代码:( G" S3 g! X4 v6 D5 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;
} 效果如下:
: Z0 y, k) j5 b! Z- |
1 G; q) o2 D% ~) `! a8 Q( X8 q5 G/ v
8 B7 U; H- A9 K4.CSS阶梯样式边框
) J6 E; C( R9 H( V" ICSS代码:% Q+ Z. p+ M/ J5 E" |
#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
} 效果如下:
5 S, U, {9 j7 m/ s
+ H& ^$ b1 R2 v) |$ y2 z3 l: y
3 M4 H. R8 `9 s5.CSS只有阴影边框
6 {! v6 ^* T, oCSS代码:
4 f8 ?1 I$ C8 h& p9 f& \#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 X7 e9 \' P9 s+ X# |8 e/ D9 m
# A$ e! z: b! c& H" o% ?
% a6 _8 ^" n Z; X3 m: B4 G6 b6.CSS带阴影和轮廓的边框
Y: v0 f; c" OCSS代码: J4 r* H: B( n& z3 A! C* n9 c
#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;
} 效果如下:/ ]8 k( h% Y" g) O3 d H. y2 M
) O+ C" N# r9 E* t
& i$ I% ?+ H- U ]# ?+ m* i
7.CSS少量阴影和轮廓的边框
" y: E' g6 P( s5 [& H$ X% `CSS代码:$ r: ^ S- x& H
#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 R8 J W& A9 H8 n7 y. Q8 i
: W5 T5 B" r" \- [$ A X' d5 U. A W
8.CSS带有阴影的双边框
7 v0 M0 h$ l2 v8 u1 V4 z2 N) c- E- fCSS代码:
5 R" @7 s9 B, C6 `) {#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;
} 效果如下:
% X$ {* U7 Y% W+ p, O' ]
& m% ~& x$ g: m2 x- J! `, M) a
/ {; m/ D% i8 r! o) I i9.CSS多色边框: D8 A7 w" ]6 Q
CSS代码:
' G5 |8 D9 S1 r' h# L1 I# 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;
} 效果如下:
5 i* p$ U" ^2 B. C
|