CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。0 B$ s$ s, w+ q! V' [5 p# `, J
以下各特效用的HTML代码相同:! `% |& Y/ y& e7 ]/ g
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
" w! I: M3 Z% U3 T( m( z3 j1. CSS动画边框
$ m+ T, f" _6 x& b1 sCSS代码:- j! G; ^) |) J, S0 u4 x6 J
@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;
} 效果如下:1 \4 O" B$ a. A \$ ?! k
/ \! ~1 |1 S* V: D5 _( F2 ~. X+ t$ C' E0 D! F
2. CSS图像边框
0 A, i# W) K: cCSS代码:
! E1 x+ T* G2 h$ a1 o0 ?( Q#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;
} 效果如下:
4 Q( B0 K* Y: W' O7 V9 N; J
. d7 T. Q0 N2 f" H3 ?! R4 E! R: C! l+ ^. U( T* x7 P" h6 a
3.CSS蛇式边框
o! r: O: n4 u5 ]5 t# }CSS代码:
. z; v% I* b9 Y/ w8 u; j5 o#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;
} 效果如下:
1 U9 w4 g; B9 m; l- Y! S0 |8 U
& x9 i, {5 e/ `
+ o8 m) ^0 a) r0 b0 @1 @' O4.CSS阶梯样式边框
& ?. E J0 z; d* C5 eCSS代码:5 ?4 S- h2 z: p8 ]
#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
} 效果如下:
. {0 ?( a4 I+ g G: y$ H7 B
+ u' |$ l! I5 m: B9 ?. M# P
1 ]# `1 e d0 }! F! e
5.CSS只有阴影边框1 B8 o2 f8 H. f3 p6 r% b
CSS代码:( Y: K m; p' o* H
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
5 l* b; O/ C2 V6 s" J! O) b5 v
& l) T l8 m6 j
1 a H% H. V7 J2 m6.CSS带阴影和轮廓的边框
2 d7 \; ~$ }5 X9 L8 v6 yCSS代码:# d( G; [) j8 a9 P. h& t
#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;
} 效果如下:
' S$ O/ @2 P% Y
0 F2 {4 \7 N% }! [. y# m: P# b& z) d$ W; r% l. e
7.CSS少量阴影和轮廓的边框1 R- k2 F+ c% C% J% w/ r; f
CSS代码:9 {% U! m" Z, h1 b! y7 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;
} 效果如下:+ ]0 z; m1 a% r! e0 `
9 ]4 T% V* _' B& L* H4 _2 r
5 ~% c) v; j# i [" c( w5 N8.CSS带有阴影的双边框
2 m; G' H0 \7 uCSS代码:
9 y4 i8 D0 x( v* T* S#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;
} 效果如下:
8 m' ^# {; @6 {8 L5 N
% |6 z$ d* _. m. C$ ?2 g# a# S: ^; ~1 h
9.CSS多色边框
0 s1 k- o3 k9 k" uCSS代码:% d3 |, I, i+ r& k" k) ?
#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;
} 效果如下:0 P: C, Q! O! [7 V3 ^
|