CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。3 e# _2 B' ~2 G9 t: ^' T
以下各特效用的HTML代码相同:
5 }: S. i% ]" j6 k# Q) m+ s<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> - g' D9 |6 r$ ]9 J9 b+ b4 E% n
1. CSS动画边框, {4 v! B0 U& r$ e) s% x
CSS代码:
& K2 G9 }! [( @; _5 {@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;
} 效果如下:8 i# h" U5 _- U }
4 \+ E; L2 n' ?- T0 e& a
6 ^$ H- y" A8 \2. CSS图像边框* `& h4 p1 X @" g% ]
CSS代码:0 k6 L( g% M, `* E; D9 d
#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;
} 效果如下:$ R; t- t# R' O2 }# D; q! B2 u
, S9 ~8 X3 o% ?6 I' J; {% x$ R* a$ o6 c N$ K, W: h- m% ]( B
3.CSS蛇式边框' N& U7 o# Z1 f+ ]; c
CSS代码:) g/ b( `- b" B! 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;
} 效果如下:
2 V7 M; |: i9 o: h5 B
- T. S. G# m7 T5 J7 ?
: \% T" R1 N) w: X4.CSS阶梯样式边框
. Q- ]6 l( E+ L# DCSS代码:
" X% A& k3 j2 {) W2 c#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
} 效果如下:' i' b# o2 d( T4 Y5 L& c9 d
9 n, z1 W9 d+ v' X9 ^9 H5 B1 m0 B* A+ p e& o
5.CSS只有阴影边框. ~. q: P2 ^% O1 z. f
CSS代码:& R. P0 h9 V; }. H9 O c4 }
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:) J0 U4 O. {$ V/ q
: w( {0 u# |7 ~1 Z L' e. k& {# i: p" [' N" r
6.CSS带阴影和轮廓的边框; r1 b X9 f: n8 q
CSS代码:
8 @* }2 t2 `1 i5 e6 j. f( q#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;
} 效果如下:
. M4 Q& D3 V& G, z4 v- U7 t, H
( g9 L5 g2 l: h7 n6 J8 b3 Y b1 s$ |; j+ C2 E& ^" i. q- M
7.CSS少量阴影和轮廓的边框
: X) o7 Z" x, k& O% m. |CSS代码:2 n- Q' s1 ^6 N1 s
#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;
} 效果如下:/ M- A8 [' I, ?: o: n# K
4 r% v, x* H1 b- j
* I3 ^& w7 o, G+ `8.CSS带有阴影的双边框
5 d: l8 R5 k; b aCSS代码:( E7 |+ M0 P! F1 t
#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;
} 效果如下:
" z: E/ X2 v9 |; d+ q
2 I+ I. h& y1 B- X! y. k2 [! h0 P
9.CSS多色边框 A- G" R5 L2 w( [9 S# n- @
CSS代码:
( K, S7 l3 w; x- w/ G#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;
} 效果如下:. v I! `; Q( D# G1 X
|