CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
! A) U C1 X5 x( x5 d7 ?, W 以下各特效用的HTML代码相同:
) m0 N( `0 @0 M" T/ [. f2 p6 ~<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
9 y: T6 ^) {. ]( ~! l' R1. CSS动画边框
1 H( b* O. y/ k4 Q2 ?CSS代码:
, ~% E9 [/ U( 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;
} 效果如下:
3 r# o' J# e* _ M. O( \( F+ ]7 V
6 M2 q, I7 a" Q9 z r4 x. T
' m+ d9 I3 }- H; h; M' T0 H* B2. CSS图像边框& j( W( g/ N9 A
CSS代码:
7 w p) U! f( v2 r#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;
} 效果如下:; G' d; n% Y; x% ^1 j1 s- |- U1 p
# Y X$ `1 L) C" G
8 T" W" y. @4 m3.CSS蛇式边框2 K/ P; w3 I; J7 G- X, h6 c" y
CSS代码:+ n0 [7 W- D2 M+ @
#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;
} 效果如下:2 a. [. ]0 ~4 r6 ^1 z
: F# d, \5 ?4 C" s$ `
5 L' E$ r# k6 m$ w; P7 Z7 P( P4.CSS阶梯样式边框2 x. ?! {3 K8 ?& t% f; V
CSS代码:. _4 `& w4 G( \& u5 q& B
#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
} 效果如下:' ^2 Z- R6 v( w7 y# V6 `
8 ~$ T) q" T: K( I3 d
% _7 _, I+ {0 c R% e5.CSS只有阴影边框
4 {# z& g, S* h. ^( _* l' L: a+ }CSS代码:
1 X7 Q* A3 {- W" |2 }% t: D/ P#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:# ?. }4 {+ g& W) @
8 T+ h8 I6 I9 N$ a! @, v% |" {
6.CSS带阴影和轮廓的边框
S+ l2 u& S y( \, d$ _CSS代码:
4 V! T3 ? c1 w1 [# P: x0 |+ L, }#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;
} 效果如下:
- Z. ^3 c& k e" q
' }! g" k* e4 X6 B
' k/ E" E2 l& a- B: y3 x
7.CSS少量阴影和轮廓的边框
& s& W- `: n m" [8 W" sCSS代码:
5 |8 j, M! v/ ~/ l5 o4 S6 M8 F#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;
} 效果如下:/ i1 R' P( W/ D/ f2 Y
- W# x4 d. K% X, A) l2 V
% Y0 z0 Q7 ^/ v% B1 A& @( T/ _3 ^8.CSS带有阴影的双边框
' Q2 o' W) N" N2 H' JCSS代码:
8 u" B+ e/ p- \2 u6 j. _0 [#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;
} 效果如下:
/ K/ Q7 B ^ C) s
# I& [) D% w) L$ _; C$ A
: q- S0 m) h: S- w9.CSS多色边框7 j6 Z7 Q2 @' W1 X2 @. K
CSS代码:
! Q' [5 Q* r, P; z* |#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;
} 效果如下:
! d+ @: Q, z3 \" f7 \9 z9 N) D
|