CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
2 U9 q6 s2 A" E' A( R7 R3 `1 I3 Y/ @ 以下各特效用的HTML代码相同:1 n# l$ ~$ u9 T" h2 F# m" j& a: f
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
8 u$ J3 Z' |" U0 f) M. P1. CSS动画边框
' x# b- k* g: G2 _. v4 v/ BCSS代码:. y- M0 p0 L9 }. M: R# R3 g
@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;
} 效果如下:- K4 w$ f6 F2 Q5 \
% r, ?4 A3 e+ S
3 T! ^9 b# w! _6 `# A
2. CSS图像边框& @3 _& K3 T7 _
CSS代码:/ d% {' s/ ^3 H1 D, H' q- C. |
#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;
} 效果如下:
o- m; X+ d9 u4 h | X5 Z
, \4 J+ k! ~3 j: a( I7 ` w7 W
' d1 o7 g% Q2 i/ ?' Y' `: w/ f
3.CSS蛇式边框
2 V3 h3 q5 G# { {0 W# e& B8 M$ |CSS代码:" O6 O9 G% H! T$ f
#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;
} 效果如下:3 ? U0 K; N0 l8 U# G2 u
6 s4 ^/ {2 `3 C
/ H8 e+ V+ E# }% A4 r, Z9 `" U
4.CSS阶梯样式边框
4 v4 F$ Y4 I! H5 r8 Q# `( jCSS代码:
7 k7 |$ J) ^, R3 ^' A) ]#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 {/ m: u- @) ~7 m+ C$ N4 p
9 x: N* w/ E7 n/ O+ S5 h, u: \
1 G" F: S2 J; Z K Q7 ?: ?5.CSS只有阴影边框$ k( y. u" Z2 ^; _) L
CSS代码:
. m( V% E2 ?: G$ t' w: e#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
0 ^( z. I% s0 q* T% N- @" y1 ]
$ {* l5 l2 b& S) ~' b
6 H1 C s/ H8 t& X" P' I/ ]0 Z& g# ~- d6.CSS带阴影和轮廓的边框4 J# l; \, y0 c4 i1 i9 f* D1 K
CSS代码:
F+ Q$ S, z1 W6 j- l' r#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;
} 效果如下:+ H' t: Y) O# A6 I% Q0 v
& H9 e* T, o, B( G, W5 d, ?7 d7 z! P- E4 j
7.CSS少量阴影和轮廓的边框
: K6 X+ C! F$ f! j4 {2 B7 g7 l P1 i( ?CSS代码:( y" M: Q& N5 }4 X- t$ T2 N
#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;
} 效果如下:$ F% G& E0 v- j. U' u) j/ ?$ V i
) B7 `( s# g/ ^7 z5 w4 ]9 N) |
' r( k4 P/ O, |3 p, X9 a$ f
8.CSS带有阴影的双边框
/ Q5 d- t M, G3 F* A% ?& {$ zCSS代码:
5 r2 @$ w4 Q! g#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;
} 效果如下:
! m% N# M0 c0 {& x0 |& M; y& i
; R+ B5 c( k5 G& A# P" M' U
. G+ B: E6 G3 Q' r* k# z% p
9.CSS多色边框) `$ L0 F; F" P
CSS代码:' p3 D. Q& ?" b1 w$ `% ?
#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;
} 效果如下:2 g9 j+ w5 A+ @( v
|