CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。 W- a r/ `( R* o2 E* e8 \
以下各特效用的HTML代码相同:, W2 _: e, w& H& s
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> ; p& k' g, j! l9 v) ?
1. CSS动画边框
4 A; S( g6 f, @1 j9 \CSS代码:
: M! x. z* k- ^@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;
} 效果如下:
' Q7 E- d9 d. c8 [8 W
3 u& Y2 K$ @' i: T0 l# x: d4 c3 \
1 N: W! ~* { D9 @2 E" W2. CSS图像边框
4 A# M2 {6 I1 X0 ECSS代码:
6 {5 u, H' b- Y; F" r) `#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;
} 效果如下:5 c% K# ?* M( Y$ Y- s* Z0 A
5 Y& g8 G) d! i) @) Y& u0 e2 ^) B* ^7 y# o
3.CSS蛇式边框" A9 q& ?% E- k" k8 b R4 ~7 s
CSS代码:; F* i( E" ]9 G( l( j5 [
#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;
} 效果如下:5 @9 R2 p& e' l+ v
1 P0 p3 [4 [0 R
9 H2 n3 J/ w2 G3 }% |* j4.CSS阶梯样式边框
; |! h x6 ]7 N `; M. r" GCSS代码:- \9 p% [1 y; U9 P6 G. ?: M
#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; p' p' a2 ^6 p
2 @& b$ K, P5 d" Z! ~9 c
8 ^) i& b$ a& f4 o1 {. H5.CSS只有阴影边框
$ P8 I/ C" {6 dCSS代码:
% P- }# k" @9 l% c& `! |. s5 q#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:5 c- L1 E( l3 p$ V, o: Y P
0 @2 K' K: R$ e1 J* j6 `" }$ P+ c0 D) a8 @; R) W6 a% p6 l g8 Z
6.CSS带阴影和轮廓的边框8 n+ A( H# Z- N+ ~8 }9 D# z1 k
CSS代码:2 h* ?! _" Z2 {
#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% f% T0 t/ X
+ E5 E( u! B$ I. V1 W
* p$ a$ e. c2 X# M7.CSS少量阴影和轮廓的边框$ E; }; | u& Q5 J
CSS代码:
$ K7 K! a* c7 d; J9 w#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;
} 效果如下:) h; K# z0 }2 G5 g3 s9 c1 ~* ]; a4 y
; I" d A7 Z& s
% w) l/ J: d& O. u, N5 o. ~
8.CSS带有阴影的双边框
. |) J- u ?3 ]# X; e2 q/ TCSS代码:3 y) t+ `: a$ ~- ~$ o8 Y* R& q: z
#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 N+ ~) W, K# f; `4 _" \
$ m7 A# f9 V% ?+ G- n: l a
( ~* {% O% S) O2 H: l4 i X$ ^( }9.CSS多色边框
; L( b R: l; {. y# O {CSS代码:/ ?* i/ H. X9 l) a/ J1 j
#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;
} 效果如下:
+ B9 E" p! Q2 P. U
|