CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。( H- y) q7 w1 D5 F7 o, n
以下各特效用的HTML代码相同:' o( q4 O+ L8 C' q# S9 n+ R
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> . o9 V, C/ |3 K1 p# d
1. CSS动画边框
1 ` |" d6 }5 s5 lCSS代码:
, c/ Q) o3 c8 \; N! A: S* D" P@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;
} 效果如下:
4 m* D" A. e: Q$ M( ~% B
& {3 `# ] d2 d z+ m8 D2 c: O$ g7 l; Y) j$ J
2. CSS图像边框
' C8 D4 l I/ r. XCSS代码:
" A% T1 F9 w" n& H! S#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;
} 效果如下:+ E* ^0 q3 v, c5 _3 n; a2 ?
4 w- g+ B* E0 ^
+ y' w( ]2 W; }4 l3 a# z8 X0 S3.CSS蛇式边框
( ]( ~1 q$ w- F7 p: ?CSS代码:
/ p, ^* W5 X* X- V4 d+ P5 Z#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;
} 效果如下: F& g3 @6 n, G, {! N' p1 u
, o. K. M, Q( G( d6 Y4 z
0 t2 V5 t$ E( q3 E4.CSS阶梯样式边框8 S3 x* e7 _& v- V
CSS代码:" z8 q- I m* b0 Q ], Q( s6 l: f
#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
} 效果如下:. F7 M" ]/ d/ j8 M n3 Q! D1 Y8 g
+ S6 i0 {0 V: }8 Y6 J: c* K+ a9 Q! s$ J
5.CSS只有阴影边框* E4 S% a2 P" p, E/ F( s
CSS代码:" H, y, _ {' U7 w
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
: B0 O5 X; h9 Y4 g3 e
2 n8 K( ^, m- a' o, n) ~7 X
. ?2 ?4 X7 n0 j
6.CSS带阴影和轮廓的边框
! [* q. f+ p% R( e6 zCSS代码:! j3 v Y b2 z7 f' V! f, @
#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;
} 效果如下:
, d% V7 a0 A! p/ R6 G! h
# e. V. |7 W; w" s" ?# M
. x! `; c8 h/ ?6 R. t9 Z7.CSS少量阴影和轮廓的边框
% M: t: n' j4 e- _# qCSS代码:
' D3 {' Z; G6 ]#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;
} 效果如下: a. u( T/ D* X" p/ X' h3 t
/ @+ S, Z9 Z, Q
$ A H4 }) Q: j4 l) @8.CSS带有阴影的双边框
5 [" f& t2 o! z8 u7 R P2 mCSS代码:
: I* M, `2 o/ ]7 r& b#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;
} 效果如下:
' p! ?6 F4 }/ v ^3 w
5 ]/ }+ [5 a. C
. U# \# C% T6 g/ [4 x9 b
9.CSS多色边框- ~2 d, w4 n* h9 Q' T
CSS代码:* W& p7 b/ H8 X9 x) v
#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;
} 效果如下:# L+ S- I, B% a0 H& t
|