CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。+ F' S" L# Q( s) U) d
以下各特效用的HTML代码相同:. C: g6 s8 c c& i4 ?; M
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
0 s+ k b0 [- N 1. CSS动画边框
4 H( v( {+ ~, y9 U CSS代码:' F8 c9 q; E" _& G3 D8 A
@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;
} 效果如下:# @, v" a1 m1 |, d7 f8 R3 g
) Y$ i" l2 F( y0 b, {) _ 6 x* u- L' Y6 D' V2 q& B8 v
2. CSS图像边框
7 a, q9 F$ T0 g0 Y- L |. O, |9 ] CSS代码:
6 ` B" }6 w) ?0 c, a" N4 _" t #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;
} 效果如下:
& ]9 k, t, a6 Y* l& c
4 }8 W; V% M. P" m; B$ X
' k7 R4 x: m1 x7 S- | 3.CSS蛇式边框 / q w7 z: `5 j& @4 X
CSS代码:- ^# D8 d. M- a" K* f# w( _' J
#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;
} 效果如下:" y, n2 ~- U5 v3 n& ?. V2 a
- \5 S6 V0 B2 q0 o! U 4 N0 H" d E4 ]' ^
4.CSS阶梯样式边框
% x7 J3 t X# V% E; A CSS代码:
z; e. @6 a4 F4 v: J #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
} 效果如下:1 b, G- L" C- J9 G
' Q& P5 J! i7 {2 d0 m; Y
/ n; F( S6 M; f! Q1 ? 5.CSS只有阴影边框
) S+ W& F l5 z4 s0 A CSS代码:
+ L: w3 k2 v! ]# \$ t #box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:7 Q& s/ b4 x* v, c$ M5 Q
8 {) k& s$ R2 x7 w |$ E ) T" U6 Z+ l; r- s) S
6.CSS带阴影和轮廓的边框 3 l" }1 Z5 ]0 _+ J; G2 k
CSS代码: i9 ]2 b2 P) n* b/ A6 E2 {$ p
#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;
} 效果如下:& G/ T; u3 x E6 e9 t7 \; ]7 P
0 B- ^) b. \( J5 a
" u' m: d, G8 j& x' b) _, { 7.CSS少量阴影和轮廓的边框
9 Z: D6 b0 j! a# P* d CSS代码:6 W9 _7 E0 k0 z, F0 w( 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;
} 效果如下:
]4 j( ]2 x) m9 \# L" R! S5 O
; J) \- e/ f7 r4 k
$ y; n& Z. f& |& z5 q7 ~+ J 8.CSS带有阴影的双边框 % ~9 @; M- t7 v% u! f
CSS代码:- u1 z9 I$ W' h( {
#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;
} 效果如下:8 e7 f4 F* @+ ]+ R4 F0 c" O
& X5 q, b- o1 N! D# l: D& r! y! C: A ' C' {% L/ K! ]* A) r* b: n
9.CSS多色边框 0 G; p6 ?. v- T* B+ v5 r
CSS代码:. F9 z. b0 k3 L# C) A0 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;
} 效果如下:
; z# ^& B/ x0 o7 ]# `7 k$ A