CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
9 l \, i) P+ h% N. J# | 以下各特效用的HTML代码相同:
2 [, ]; _4 J1 T* f, X- M- ~ j<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
9 Y2 D5 f6 \: [4 `1. CSS动画边框
8 C' i& D4 R$ d! d2 i! HCSS代码: s) p' ^0 _% h- L; ~+ |
@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;
} 效果如下:5 o& R+ E0 {& |3 L
, N0 J; A5 d# C0 K! J
8 d3 e7 N/ x! A+ S$ p- _# p: h- r
2. CSS图像边框
/ h9 \# c. d3 N0 M: o# r2 s5 {9 l, MCSS代码:
0 F' F7 Z1 d; t" `* a9 u/ E" `#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;
} 效果如下:
% d. P% Q8 s2 B6 a3 v+ z! M
! {9 X4 x" ^) ]% h$ K' x
9 a9 g" ~0 {# ]6 [7 q8 F$ n3.CSS蛇式边框
6 `8 }1 u2 n+ q) BCSS代码:
! ?* Y& m4 X5 c+ l% i$ r$ ~#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;
} 效果如下:
% S7 d2 L o6 @, c8 Z7 e4 P$ W
$ P) J2 Q3 g7 I+ ~2 r5 M9 j$ `( z/ B& Y- D" }6 e7 a
4.CSS阶梯样式边框
% ^0 F. X ^5 B& SCSS代码:
6 ~$ M) w- h* c7 n- {; U ]#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
} 效果如下:# `/ q# d3 o( T2 z& ^4 e8 b
0 ^3 N; E' z0 i8 Z6 H) L
& R* n& {, x9 e( I+ A- y5.CSS只有阴影边框/ S9 {. U& u' I4 `' m) U
CSS代码:
! ?5 [4 U. c6 [& M: R: c#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 h4 X, x' f& V# m$ J' C1 H
2 \7 [4 R# W( H: i
0 g. ~* L7 s4 W0 }6.CSS带阴影和轮廓的边框$ i8 U3 f3 w- i1 H# A
CSS代码:3 C" S# ~8 b, \$ E2 P' }. J 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;
} 效果如下:
) j% K0 Z* L: F- K
- s/ ?& Q& V5 }; Z! @
. U8 ^0 c7 \! M1 F5 b) m6 ~1 [
7.CSS少量阴影和轮廓的边框) B6 q g( H# `5 Q0 U N/ r' S% [
CSS代码:* K: E( L) w6 h, C! c1 _
#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;
} 效果如下:
7 L+ H: H4 }8 [5 A2 v7 E& c
. r) v0 K4 P# N A3 e5 j
) Q0 A4 l6 N. V+ r; Z
8.CSS带有阴影的双边框
7 h( k& I) W. W, hCSS代码:% d0 ?' `8 p. J- D3 d! J" n
#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;
} 效果如下:3 C+ A: S d$ q5 a+ k
; i/ v* } U7 T. a& J2 l0 t/ b( E0 b6 ^2 M
9.CSS多色边框
! [. f6 t3 D; a2 e: N. |- `* G# `( z0 YCSS代码:* f c5 T5 R! w( v7 l" H. p8 x
#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 n, }: f* b& D Y6 _
|