CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。! R' `: e6 k* ]# v
以下各特效用的HTML代码相同:
9 R0 W; D7 T3 n<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 0 |7 \# v c" c2 s
1. CSS动画边框
) q t+ G1 u* _' |$ U3 @. ~CSS代码:4 e! V2 G8 R0 l; U0 e7 ]5 l* |
@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;
} 效果如下:3 j+ @- i% c1 L4 r$ R
4 W L! V/ B: a& J0 R" E/ T/ k$ X% X6 a- ], [7 L) z
2. CSS图像边框) \7 f* T s4 s% O
CSS代码:
) Q# j7 O/ L* S) c- B3 s#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;
} 效果如下:
- p. G0 \3 \! M' b M
/ u: i2 U- q. A% l
, @9 X2 h5 Q8 u2 d K3.CSS蛇式边框
4 q( c3 O: x r- SCSS代码:
$ ~' g+ Z/ B8 E; g8 `6 f#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;
} 效果如下:+ q- W' G0 W! Z. ~4 h- h: _8 d
. n; P7 G' @. M3 k% o1 C: K
) d0 C7 S$ [" p9 f) B" |4.CSS阶梯样式边框; v9 l& Q- u' Z8 a5 W
CSS代码:9 i$ \) ^4 Y; S. \' G3 Q. q
#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
} 效果如下:
. `3 i7 j' c$ I8 L. l! X
% u; ~* V: C8 k( l9 t: S' n9 e5 X3 \
7 a6 J% B4 E1 Z% w* ?8 A6 W
5.CSS只有阴影边框) V6 g" G% X8 r. @6 N
CSS代码:
n1 y! k o: a* \& w#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
& H3 H+ Q2 ~0 Y
@/ R: _0 \4 ~5 U2 l8 _ i3 ~8 Q9 @
6.CSS带阴影和轮廓的边框
W. D8 a6 Y7 N j% ECSS代码:
3 y2 ^1 k( h5 e* K- W. X8 A, 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;
} 效果如下:
! C$ M7 \ I, A' L$ u
3 H+ |" i/ m% h) p# v
* P4 c, V( m/ `$ f/ K: w7.CSS少量阴影和轮廓的边框! b3 q$ A% @0 @* K3 a
CSS代码:
/ X/ g- g1 o# M- I0 U0 P#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 |1 q4 t! l1 Z0 G& B1 J
. c) \, o4 D" d; x$ {
, v, V7 f* H; l
8.CSS带有阴影的双边框- |9 S. ?1 v! K* a
CSS代码:
, D% W0 G* k' T1 u8 z9 d#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;
} 效果如下:; D t' d$ ]' t Q7 _
W9 w8 z) v: g; \/ c9 P1 p0 h' v# d. F: }- ^! y- q+ i9 G
9.CSS多色边框
+ v, L3 L3 }. bCSS代码:
8 K* ^# G$ }8 O! g0 b7 @9 n( _: |#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;
} 效果如下:# t1 ]0 w( l; ~/ f' Z" H
|