CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
! D' U- ?( ?; v# _9 B2 l9 N 以下各特效用的HTML代码相同:) h; j) ?. c) E/ n& ?7 x
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
( g! h: d: z- Y9 n# H. u% |5 P+ E1. CSS动画边框- M5 F5 C1 i1 B1 ~/ r3 G
CSS代码:
7 I8 `9 C2 Q. h( P@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;
} 效果如下:
* H7 L; r& S$ @2 N6 l
7 I+ Z$ n3 a* `% W; }' s
# V' M$ Y1 h1 R: t& {
2. CSS图像边框
7 c. p, k' f6 N* m: G: DCSS代码:
9 F1 C- d7 V) e" d& b+ r! P# z. J#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;
} 效果如下:
, a) c) g4 |2 a/ F( H) }# ?2 C
g7 h H# E1 O% x1 O
! W/ ~1 O; l( J- H3.CSS蛇式边框" c- `1 m3 \7 e7 \! _" k
CSS代码:" P5 \( b1 s n1 M9 X; w, ^
#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 F; w+ e7 j- q$ N1 V; q6 ~
. _3 s/ J& Z( F' x2 M! o9 d, w
- u: @" U: M) K" @" ?7 y5 M, Y4.CSS阶梯样式边框 i l( G6 `+ Z+ P0 |
CSS代码:
# @% k) t- \! Z& u' C0 k#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
} 效果如下:! k: [) e7 n$ F& r; S
8 m# ?, j9 \" K# x n% s. L0 q
. J5 L( L1 s: r, ~; ^
5.CSS只有阴影边框8 G1 q Y( z: f! _7 e- r) _8 `
CSS代码:5 L2 L" k3 s8 J/ |$ `0 V( [
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
; q# l3 }- c4 w* l G# V
6 B' f6 a7 G0 d, p! w
( H e0 t) f8 d( y5 ?6.CSS带阴影和轮廓的边框% C4 u, `0 ^ l
CSS代码:' O: ^! `1 O! `4 e, |
#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;
} 效果如下:
) J8 j. J, r: Z) l* v" `
! [$ }. @' L @* V
0 C7 J+ q! U7 S! q3 B2 Y5 v7.CSS少量阴影和轮廓的边框
, U2 d5 N2 m+ E1 O. a8 T; |, x- hCSS代码:) y; J+ z4 e! R3 E
#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;
} 效果如下:7 t& l+ U1 N# u' j. L: ]9 P0 f
! w) x3 x7 J8 h' G# j. k. w
$ m: ]3 ]0 M, f* b* f8.CSS带有阴影的双边框2 ]5 T7 a( j+ o3 C2 S8 {% m$ |
CSS代码:
7 r7 ~; |* k- d/ Y! x' b+ 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;
} 效果如下:
2 }% ^5 _7 Q- C1 I! `1 }, U
+ r# d0 S; ^% R4 p q/ k4 J2 J/ \; f9 x9 `# h* x. }0 m
9.CSS多色边框4 H$ ^9 B' N0 V7 P+ R# q
CSS代码:
2 B& Q( }( [( g 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;
} 效果如下:
* U L, ?1 y4 k7 p: Z! g9 F# Z6 Z
|