CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
. v1 j/ F* N7 j( Z 以下各特效用的HTML代码相同:: ~$ _7 Y4 \( a: U3 C
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
+ F4 O+ v4 ?/ @: d+ Q1. CSS动画边框
8 A% ~5 d. i& X5 F/ RCSS代码:
2 L2 O6 M7 `9 J9 L+ A) K# o@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;
} 效果如下:
. O) C+ O2 l( ^8 t+ {" V
: [6 E% _( A, Q S1 p9 P- `
& r. U2 m6 k& v W2. CSS图像边框- }# ^4 O9 ?% |* O% H& s2 |( h
CSS代码:
5 ^" G% J8 z( U#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 |, ?" v P. a8 i+ \2 W
0 _! s' I/ k% j N+ X) i2 z! F
6 h6 p6 u: W3 i+ I& [) n6 I3.CSS蛇式边框1 {2 h7 J+ a* q# b
CSS代码:
/ W& [! R9 D4 E#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;
} 效果如下:
: ?, u9 ~3 d" C* e" P: V7 v
' V5 K. A( [4 a J' a: I9 [7 t- H( |! I' X* i6 r9 _) z5 [6 L7 G0 L/ V
4.CSS阶梯样式边框4 h7 Z; p' i x: L, C
CSS代码:2 W6 `2 X( |! n* I9 X) |) p9 f0 {
#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
} 效果如下:9 b$ e' L! \6 L: ~; t
5 J& B8 C4 o& }# Z0 E/ z% {% k
# A% o! F+ V2 D! p
5.CSS只有阴影边框
( O9 s1 h# {# J6 \5 zCSS代码:" n9 R( f0 K7 _0 S. C) 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;
} 效果如下:2 o. f& j: B- _" N% I8 e
0 V( K- J7 {7 A3 }, o0 b; v
- l& G/ q& ?- C9 P1 d6.CSS带阴影和轮廓的边框$ i' {, N4 n" \$ B7 D! }- [8 H
CSS代码:! ^6 a E4 a/ c4 h
#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;
} 效果如下:+ M) l% P/ [7 i0 \: B3 F9 q9 F. \
" W& i7 ^: l! U1 `+ J' Y. d) A3 }0 G9 o! v0 u
7.CSS少量阴影和轮廓的边框: w% m+ l ?- Q- m$ P
CSS代码:( ?; n/ @3 ]* R9 D+ q4 ?
#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;
} 效果如下:- D3 Y9 {# c) p* P! b; B
' @9 J$ ]. ?; o( T# F
2 i; ?7 `- K. \8.CSS带有阴影的双边框
6 B) V7 R: y3 BCSS代码:" M4 P3 r+ J8 |" Y6 ^
#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;
} 效果如下:! X9 z6 K0 `" Y$ w( h+ b7 S
! @4 _7 [& T: P# r5 k' z
8 [+ ]" V& g k h$ l9.CSS多色边框5 F ]' \/ x7 \: ~4 N; x
CSS代码:( N' P3 f1 S: U: `1 L% o
#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;
} 效果如下:
. K5 D# k4 a" |& c. Q' P1 z
|