CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。; O) U, [" w4 }3 ~8 x
以下各特效用的HTML代码相同:* I: s; C9 l! \# j
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> ; b: w( J; k" y0 y* R( z( {) v
1. CSS动画边框* a0 W$ g1 I' D" v) I. D# ^7 L
CSS代码:
: l9 _' o5 f9 n g@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 y. x, e/ S2 {+ g* t( p* t
; o/ i6 K4 @" L( }; K
3 y- O6 L( G5 _0 q2. CSS图像边框
0 k/ m9 s# x. M! y$ E" r h, ZCSS代码:& _/ i6 Z9 h1 y% X! r6 l
#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;
} 效果如下:; }" Y* u$ `- m) }
1 y$ D) j0 c' \* A% ~# m9 d' \
. Z+ |6 ?$ x) G/ ?# |
3.CSS蛇式边框
3 s! W: U/ h6 p$ G4 FCSS代码:
& P' o1 h! X5 J+ x3 @' X1 R {) K S#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;
} 效果如下:
) ^4 r! W) m" |+ T
4 Y) o m4 V: @; W* Y" y" |
( }! i. B2 S2 `: z. O! P9 N4.CSS阶梯样式边框8 T Y0 s; M( T/ _) B1 x
CSS代码:
8 f. s- \4 F1 {. {#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
} 效果如下:
# v# D9 T1 A* ?& N1 D
/ E* i( D1 G5 S
" u0 p7 p1 ?/ u# @- ~; m
5.CSS只有阴影边框2 Z7 T6 l3 v! ?) E+ q$ F7 M
CSS代码:
/ D% M6 @% u+ n D- \8 o#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 T$ p# l( p( V/ C9 J
& j1 {# k+ e9 G
! x; [; K" [. j) O8 G
6.CSS带阴影和轮廓的边框
' N" _ A" P$ @9 ACSS代码:
; G- o' _1 E6 `+ j, G/ f/ c# b5 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;
} 效果如下:
4 m0 f: I% j2 [! _) ~
8 m+ C% X0 E5 T1 _4 @# N' p
+ L/ }% A4 n# @" b1 Q7 e2 S
7.CSS少量阴影和轮廓的边框
( D w9 @4 e* T& b' ?! a4 TCSS代码:/ M# z, z, t5 Z/ T/ M& s X
#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;
} 效果如下:
i! I; _) @; Y# e& Z- I1 L" m
8 F; F) }$ v) R9 O0 U& y+ r/ i& i2 }
( p$ j5 p8 V- A) Y" w1 n4 `8.CSS带有阴影的双边框+ [: ^+ U( M" F4 A
CSS代码:8 c% k' y( [2 j% d5 D
#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;
} 效果如下:( } D7 k P: |
- u& C, I$ o( m0 x% G! L) c8 O
; L1 I* ? @+ [: X9.CSS多色边框
/ J# y" j9 G) R5 S) e1 y; JCSS代码:
% L9 _& A3 O$ 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;
} 效果如下:9 o# Z1 \; _8 F+ u4 f5 @! E
|