CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。( a M" l5 S- q! F
以下各特效用的HTML代码相同:
$ f" e7 `/ ] i1 d# ]<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
$ J5 A' l& A# u1. CSS动画边框. l; [( e. R; N, l8 o, e: t
CSS代码:
% O# G/ @5 S& 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;
} 效果如下:
' K' R7 r& v' S* f. f6 D0 z& B
/ S$ F9 {1 c' S1 ?6 Q4 Z# Y
8 T( i( g( T# [! H2. CSS图像边框6 o$ [3 L; v1 i/ L
CSS代码:
# H& D0 u( e0 W2 W- o6 o#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;
} 效果如下:
1 X0 U$ S* {3 e r9 c( Q1 \8 l7 t+ u! C
6 Q2 s- q! y* t
3 M# r H% s$ g" W
3.CSS蛇式边框5 [, |/ [$ \0 V) R x5 U" w
CSS代码:# x/ M2 d. e" j. a1 K3 C
#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;
} 效果如下:! y5 a/ v4 B5 D2 i- W# D( s
0 {& N; {. i6 C3 V" Q2 ~5 }5 n6 |- ^
) r" C( @- H5 j2 O" F
4.CSS阶梯样式边框
& U! O! d+ Q, P) S: h) x4 p QCSS代码:5 X9 Y4 x, ~9 m9 e# r/ G" D$ r
#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
} 效果如下:
" {- l! e5 v3 g- R# M% r( ~
; m- R& G: `8 ]8 b6 A2 y. W. F! P8 m# O$ n4 \; X
5.CSS只有阴影边框! n5 x; o \* n* s0 c3 u+ _! b: r% D
CSS代码:+ s8 p" z0 z5 r( t' I5 a
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:- b6 p" B9 ?6 M3 O! k0 H7 B# B; K
0 z8 F/ o/ O! ~
7 b. \) ?# I+ w6.CSS带阴影和轮廓的边框; H/ }$ a* P" _! J( W# @- C5 j
CSS代码:; z7 U8 ?! z, m/ @7 e+ M2 K
#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;
} 效果如下:5 I, z0 a5 N& {$ |
5 A+ |! N& V9 |$ M+ d
& u+ l* w9 Q/ Z/ s! c) \: I' w7.CSS少量阴影和轮廓的边框
- d, m& m' a0 C+ J* C1 R6 UCSS代码:
% K$ a) C M1 n N( a: V0 t#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;
} 效果如下:9 Y3 I" i6 S" a% |- R" E8 p- g
/ T8 o6 B: C7 N a J0 c; P @- k- o8 ~2 ^
8.CSS带有阴影的双边框& N( i/ C% u( O" e& l
CSS代码:
# A% l/ |: k& j8 ]#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;
} 效果如下:
0 ~9 _! D- \( J' @0 ~6 m; m
* g3 B0 X6 `5 R: X4 L3 I) Q* z
( H, I4 H. a1 [. y2 P9.CSS多色边框
- R2 f4 L m6 Q& Y" S {CSS代码:
, u7 M# M8 ?* G* V; y" C#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;
} 效果如下:
3 k$ W3 n1 U: v% b" X* i7 Q
|