CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。/ f2 [( k1 U3 z) V0 d; D2 T5 Z; I% K
以下各特效用的HTML代码相同:
6 n# {3 L, M! }3 e7 ~% `<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> ) h7 f4 j) Z( L. z
1. CSS动画边框2 W5 d, {8 l. A0 r8 Y
CSS代码:6 S. E0 v" u" P0 `
@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;
} 效果如下:+ Q1 A* t, k" B; o: D
2 l' k6 [% p" r
1 _& X/ v- e5 P& H4 {8 c9 J2 l! M, f2. CSS图像边框
1 U8 p% N9 Y6 ]) \% l5 l- rCSS代码:+ n' D% T/ @9 {& l' I% I9 ~! \! C
#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;
} 效果如下:
: ]* Q0 e" B3 G. `9 \
. O* o" M r% D: S4 n: n& @% p+ ^1 B* S: W( W* F- p( d \
3.CSS蛇式边框3 S3 S8 D; K r8 B. d7 E
CSS代码:
" }. E6 Q% j; M2 D3 Q#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;
} 效果如下:8 x' V7 |0 \# H, F6 t
' {. r( J. E: U! G2 \+ P( r7 r/ p J, x' d! m; `, B
4.CSS阶梯样式边框4 j8 F9 a& e! ? g
CSS代码:- y/ T$ v! V) I5 R e( Z% 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
} 效果如下:
: q6 s) i0 ]1 ~+ [
3 z+ i9 ?# i* s! _ [, l2 J6 e
7 S0 M- @0 G3 Q z% L' g) n4 j
5.CSS只有阴影边框# _) p6 M8 f8 N* z* D7 f5 P4 W
CSS代码:0 ]" t7 Y0 z5 ?# r* r
#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; U/ S; g: g/ W# c; \4 {
# N8 c9 n+ i4 D, s9 F, L' K) H8 z* S0 J) _7 v) p+ r; j) s, w
6.CSS带阴影和轮廓的边框$ K. s V/ j; D
CSS代码:' r2 ^/ L- q! {+ ?8 ?( j
#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;
} 效果如下:( U! s5 y6 T. D( u5 e8 _# E
- f! T$ x6 a! l5 a7 \% s$ R7 g1 L0 z0 k( K9 O# c; q
7.CSS少量阴影和轮廓的边框- N, R) x" h2 Q$ l& m2 Z
CSS代码:5 w0 z% Z9 b4 q! 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;
} 效果如下:
8 E2 K4 W7 F0 F- Z5 t2 r& m: \+ |
5 F, h) o C; O+ N, Y
1 J5 q) ]8 f5 c" Z8.CSS带有阴影的双边框- S3 K! u+ g: v' e: l+ a; g# K) R; Z
CSS代码:- ^$ e/ F# s! r6 a! I$ x' Y
#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;
} 效果如下:# q+ W; C% E- h. J0 t" o. B+ }# x
* o% \" k# P, o. k3 k* C6 i
' f% w) ~% a" V; F
9.CSS多色边框, }* ]2 B! {8 ^+ N6 {* u3 D9 Z
CSS代码:
( q8 w% {# e( P# B2 [5 b#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;
} 效果如下:; i0 v7 s+ K R \ F
|