CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
: H2 F2 b0 X) v. @ 以下各特效用的HTML代码相同:1 |* R9 J [$ ~- ~: |9 h
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
( i7 x% X' Z. |9 C. J5 ^, g1. CSS动画边框
5 `+ W& M# C+ w4 a' @$ _CSS代码:
# b* s5 w/ d8 a2 C- n) y, m@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 k# i( Z0 z2 E/ Q( r2 u( d
5 S9 P, ~$ W$ g3 R( e
7 B4 M/ L" @ J& X3 l2. CSS图像边框6 x# G K+ U( ]6 b
CSS代码:
G6 ?. l9 J) m: F& k N#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;
} 效果如下:8 d# o" m8 Y0 \$ i; k2 Q
( C* p3 d5 d( X
3 m4 [1 \( s( J2 r3.CSS蛇式边框
. t3 L# d |1 c8 B* h- S0 v oCSS代码:
- q$ p. l' W0 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;
} 效果如下:
) F8 C1 H" t+ I: g0 }4 d/ f T: @
1 R1 I! p8 ?& n. n/ @
- O7 [; m# g, q4 |( y) P
4.CSS阶梯样式边框
c2 a) \ ~' W/ F" x0 S% D9 `$ \, iCSS代码:# g3 o( w7 b/ n; W9 U Q' _
#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
} 效果如下:
4 G2 O1 d4 E, |
" }' X9 j/ I$ ^& v% K1 m: ]
( q7 Q7 m! e) d+ S0 [# |" J' D
5.CSS只有阴影边框
+ o7 y3 B1 l/ W- q. v- c$ R% r5 eCSS代码:
+ s2 G* ~: z' ~( U#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:, p# O2 b E h- F
7 A0 }+ ^5 T, u) z
: n* E4 u' q& T9 h! K, A
6.CSS带阴影和轮廓的边框' F. {! Y2 O2 S! G
CSS代码:
# @2 g4 E4 F+ r% 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;
} 效果如下:
" S. m7 b: Y- @8 s
& I0 U" p. T( o! v& {* U" m
l" G [% ~9 P1 _2 B0 W0 H7.CSS少量阴影和轮廓的边框# b0 r! j# \0 i) H6 f
CSS代码:2 D4 o8 {; k- \; Q; c
#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;
} 效果如下:! P% |! `* C# q& @# j
X; h* O# N; n! i! ?$ |' Q! |; ^9 Q$ F" Y) H) E
8.CSS带有阴影的双边框
/ ?2 {% a+ i" WCSS代码:# r4 |2 T3 n( E+ O7 r* t' M
#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;
} 效果如下:
9 t9 |7 n+ m( _! u+ x: _$ m
1 u$ @# k( j: j1 ^% Y4 R- I/ j0 {1 m6 H* C! y+ V; G3 i n8 ^
9.CSS多色边框
: k2 k+ k3 j, X2 z( l4 kCSS代码:! T1 F# ^1 y& G, i$ @
#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;
} 效果如下:. x6 r3 C9 K' O7 @+ d/ q
|