CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
% Y/ l9 d0 ~/ Q! P: ` 以下各特效用的HTML代码相同:
3 X# }) L% V u5 x<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
( Y/ c `' g; v* l# f# T1. CSS动画边框7 N3 U) q# r" d4 h
CSS代码:/ |' Z9 n6 E1 A3 z
@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;
} 效果如下:6 C+ i0 Y! \) f' V! y5 A* a
c* P" w @9 s1 s$ |' w
* V5 K3 m9 [: `/ s2. CSS图像边框+ |! n9 g |& f% u' a# u
CSS代码:
! J- n: O3 t6 g5 a0 R6 A#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;
} 效果如下:- o4 K! h$ p) j3 n6 A* [6 g C
' v3 P6 x" }5 C) ^( M
+ J8 G' A1 l- L) G: t, O+ i8 [3.CSS蛇式边框; e/ {+ J! y# A) l9 l
CSS代码:
. k/ l3 \$ H* I#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; h% n7 q! e* `7 O
( A; u. _) M+ b3 [
$ h0 P Y1 \- I0 |8 M, W4 j% j) K; ]4.CSS阶梯样式边框
3 B( k/ W$ F8 T& K6 r; M9 ?CSS代码:
, `, ]3 @- \/ x& y#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
} 效果如下:
. t$ e$ a; N1 ^
8 p2 O( b$ J; K1 P+ k% Z
+ H$ p( S7 F3 z2 j7 n$ l5.CSS只有阴影边框' A% Z2 A0 Y) O; p3 }1 ~
CSS代码:- d9 O2 w3 t5 e9 s2 b
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:. F1 z3 b, R. h
. T2 t7 w1 m9 ^0 ?8 G) b- O/ J
0 C) z1 h/ b; a3 Q0 Q! p& `$ s4 t, l' ~6.CSS带阴影和轮廓的边框
2 }' M7 d$ N [; D( F* MCSS代码:
, b; n" S C. H* {- K 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;
} 效果如下:
: P7 B' r/ K& q1 [( j
" ^7 a! `- v: _& @
8 v3 s( a) B: }' v
7.CSS少量阴影和轮廓的边框
9 j2 o( k- F+ tCSS代码:
+ ]% x$ F+ n/ n F8 M#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;
} 效果如下:
# t# w3 O; E" l7 k
& N' A+ g5 d/ J! f( H5 D Q4 |, d! X$ [
8.CSS带有阴影的双边框, N: G2 U5 N; s0 }1 x9 E
CSS代码:6 n" N4 g2 b% u
#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;
} 效果如下:
! W: A; X( b# l$ Z
" F# _# l. e; E- i) O4 x- j8 g2 [6 G: {- Y) ^* H
9.CSS多色边框+ f1 c' [6 b: h% w% O
CSS代码:& s( P& G! h5 P2 [+ J1 o
#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;
} 效果如下:, i& j# ]/ P* j) `+ |( Q0 y
|