CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
9 W0 D& X3 ~' B5 v3 a$ O8 \2 ^ 以下各特效用的HTML代码相同:
8 C, @5 K$ W6 J9 D <div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>, v9 n+ m4 R, c0 u& @3 Y: c6 T0 R
1. CSS动画边框 % \) c9 O5 p6 R& {$ t
CSS代码:
9 K) n0 n. C+ ?' w' e' V @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;
} 效果如下:6 c. ~" B2 U$ H# f7 U) Y# l8 q
; @# {& ?5 B! u( I* t) N+ _
) X1 Z& B9 E: W 2. CSS图像边框
- T4 ]: Y* ~9 {* p CSS代码:
. R. Y" J5 w. [# a+ ?6 D8 N8 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;
} 效果如下:
( {$ x. g& T) I+ _6 A! b
g4 a6 k9 _2 Z& S' e
& b2 J4 g5 l" M R- b; V( ` 3.CSS蛇式边框 % }* |! U5 |' N: S3 m( n% |+ u
CSS代码:) e' \0 n. b0 B Q+ c6 F# u5 r
#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;
} 效果如下:
& U& K. S' k6 c
: n, u1 x4 y# H% Z4 p% S% G* h
7 a; V U* }/ G+ Q* ]5 n 4.CSS阶梯样式边框
# o/ @- C/ ~, r CSS代码:
% _ o0 W7 w4 U/ H. 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 D& b3 ~, D! }9 e- l: ?+ w
* Z) M2 t0 P/ a9 R- E; c
6 c2 G5 d6 Y) {% Y6 B
5.CSS只有阴影边框 b6 U. `' ~2 v+ \8 Z
CSS代码:
# l( @ _; f( G, o3 {5 A #box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:8 N. _% X! K6 M" c5 `; Z+ {
' E) O! c8 [+ ^- [
6 b2 Z4 Q! u( m/ P# q 6.CSS带阴影和轮廓的边框 9 G& ~8 D5 }, U( z2 Z% a
CSS代码:
* h4 p9 T' p8 T& n+ }" g# a$ E a2 o #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;
} 效果如下:' H O2 @2 S* Y/ Z5 v% e6 d7 U
+ r, P- w2 F/ T5 i - \4 @3 ~/ A2 h6 e8 {
7.CSS少量阴影和轮廓的边框 4 i" `3 p: t0 R7 ?6 `# }
CSS代码:
9 L5 p4 R' m _* v/ E5 r: N* [1 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;
} 效果如下:( E. R2 _+ i3 T$ X* D- [
. G* X' R+ _ r4 j
* Y( _2 {3 A8 [1 p! |6 b# Q 8.CSS带有阴影的双边框
' [0 D$ o/ p: ]0 y CSS代码:
" `8 e# J& ` q; L0 R+ d, K #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( r) I; C$ I2 L. M ?: M g
" r5 p% Q8 I' e h; k& J0 k, F4 \ % L6 M, Q- A0 j b) \* `' {
9.CSS多色边框
- C$ i5 N3 U4 Y- Q# \' d0 ` CSS代码:
: n, |2 w2 o1 }7 L7 i P' e #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;
} 效果如下:: c8 [! q, e! T9 ^3 O+ j4 h. B