CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。+ B5 Z' S$ R; \* l( ~3 f5 D8 C( }
以下各特效用的HTML代码相同:4 n' C) S+ B V9 U& H
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
- o* b: V! q/ Q: d2 ~, Y1. CSS动画边框. V$ I4 a+ ?! b7 J
CSS代码:8 w: p+ J+ q' B! J1 y9 q3 H
@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;
} 效果如下:% K$ b x) u1 y- e4 ]/ u4 @$ O
0 c$ g5 Q; W* T8 k( q0 E! a, i7 e3 Y: I W P
2. CSS图像边框5 |# U5 Q1 S/ k8 Y/ F- T
CSS代码:
1 Y6 Q# f( c: T. o( O. j* Q#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;
} 效果如下:
/ y. B& s" g9 P0 j; K1 T
2 p, z; B- I/ I J/ F: H1 O
5 I+ r# v: K/ s1 w1 y3.CSS蛇式边框+ C# c3 }7 {, k" J6 x, m) G: P
CSS代码:* {$ r; g) ~! [! f; g
#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;
} 效果如下:) k* ]" [1 u, w0 ^/ E+ c: N9 }. K) Z
, ]% X; W+ `4 m3 m6 n& v( V$ v+ b
* ~/ f. ~- {* n. u, O4.CSS阶梯样式边框
5 w. |6 F1 \/ hCSS代码:+ c P7 r7 T7 ~! h
#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
} 效果如下:
& j" }' }3 n; Q+ I1 t8 j
, d O' o6 R0 t) v: K' h
f5 [$ ]- z- ?% c5.CSS只有阴影边框
; @5 e% B! Y% d MCSS代码:! \, N* I6 R; e/ s
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
' ]9 ~1 R ^/ ~0 m; P. S! K
# A/ l: w4 L: L6 P+ X
; z( u$ W" o( ]3 C5 T) J6.CSS带阴影和轮廓的边框
' j o4 u. v2 a W; i& }CSS代码:4 g& x- F' S& d9 D* C% T
#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;
} 效果如下:4 X& y* Q# k4 s2 o$ G
( w R4 ?# _/ R5 W* a$ ?! s; Z
" O; C0 _7 Z1 R8 s, W& H* r L7.CSS少量阴影和轮廓的边框
$ H$ A4 a4 K( b, G, A6 N( {CSS代码:
1 _$ ?$ D, l2 {% h#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;
} 效果如下:6 o! y% Z* G+ f! {
L' Z |$ `. l% {" q; K- q
$ Y |& R* `# l6 T% ?* Q: J7 R9 M& F
8.CSS带有阴影的双边框
6 b6 W/ E5 b: y6 J: @CSS代码:
+ m$ b: w2 @+ o1 W! }) [; a#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& L7 m+ C& I$ h x6 u
: c* f, r( q- ~6 K
# C7 ~5 l1 ]: ^! Z6 Z9.CSS多色边框
& I3 }! R- X7 R7 n OCSS代码:/ a8 [4 c3 B M
#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;
} 效果如下:* C+ R) v1 e) p! x
|