CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。3 t) [% |) x5 U O" D* T
以下各特效用的HTML代码相同:
6 h& x' u8 e2 o1 O! n, q& @<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> ) K6 {3 N8 f! s+ x/ i
1. CSS动画边框
+ ]5 B( }! X4 E3 g! D- dCSS代码:
- G6 L- E( ^9 O: K/ h* F@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 |& C- I0 S2 l
7 F5 v. ?4 @% \
, A7 g9 @0 w- I6 D2 `2 Z1 s2. CSS图像边框! z- W7 |; S2 H# |0 Y
CSS代码:
& i3 \+ I! \; L4 K8 K% T6 W#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;
} 效果如下:% r( L* {4 @; R" j+ O3 h
; F. A& `0 R$ c) ]4 j) u; E
) x+ w" m' b0 x1 i/ V- {3.CSS蛇式边框+ F$ H6 H0 @6 u0 ~
CSS代码:4 |+ z1 o) t1 f) X+ S0 I
#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;
} 效果如下:
* x" i# D+ s8 Y: b
! H! Q+ d; U2 e6 ^6 B& ], y6 u; Q8 [9 _
3 b, ^9 I1 _0 x( m5 r( v
4.CSS阶梯样式边框
% x& C: h z3 C1 p# `CSS代码:
3 o+ |9 i6 F7 j#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
} 效果如下:% F3 i; N. J; x
^) e) b% f6 `
- j& ?9 P; O: i5.CSS只有阴影边框. y" {) [6 W5 s+ \. G
CSS代码:
4 y) ]8 c4 u7 Y; T1 T+ e' 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;
} 效果如下:, {+ \2 J; J5 e& h* v
% X3 W& r- T- [! d4 a1 T! p
# x8 k0 Y2 g+ k! r: \
6.CSS带阴影和轮廓的边框
s- W; g2 I9 _5 A( U) h: jCSS代码:8 [8 i# M9 a) @1 y. b6 ~
#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;
} 效果如下:3 {/ H) g! ^+ ~6 E* W* N" p2 K2 F
! F% ^4 k% D( \% g
. [' G8 r+ N6 w/ r$ |7.CSS少量阴影和轮廓的边框
8 I6 A) K. U1 P+ c, F* _CSS代码:
. u) G8 w3 \& w% i+ H8 f/ L#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;
} 效果如下:( M' l+ r9 K; R' M# j \: S0 d
' A. B$ P' V9 f- a' L. o6 D* f
! B" G1 Z& A7 w" y( T& t1 {
8.CSS带有阴影的双边框
# ]/ z. x" N) j- @CSS代码:5 w4 M6 ^5 N0 k
#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;
} 效果如下:4 f* l" i# d! R9 p
$ p0 y! h2 Q5 Z: U
. J4 u+ T) u% ]" R9.CSS多色边框3 x# X b X+ ?
CSS代码:
( O3 m& v! ]% W$ T7 B/ R" ~& o#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;
} 效果如下:: ?/ A- m5 `# X: ~) _( T5 W
|