CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。$ `2 j' Q4 }% G5 w( z, J/ P
以下各特效用的HTML代码相同:$ K. |4 n. i5 i/ Y# `8 v
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
5 j v. [+ h" g2 W z1. CSS动画边框
! e9 W+ u% J3 r% C* YCSS代码:
4 z% e, A$ v J@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;
} 效果如下:7 w% e* U$ U; H7 ?! y
/ k; D* h3 f$ f3 c% A
; m8 L A- _1 T: y( Q2 c2. CSS图像边框2 h+ Y/ ^6 k: z3 B1 S+ ?
CSS代码:/ E B' a& e2 k8 j) d
#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;
} 效果如下:* `( V$ z2 G9 ]( q2 t
( Y8 f9 G* ]8 r v4 d7 _/ [: o$ s$ N$ ^# i
3.CSS蛇式边框
/ e5 b G9 M7 Y& d0 jCSS代码:
& s T) I" `0 C; i7 ^+ Y$ n+ n#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;
} 效果如下:1 _$ o: x4 ^" d4 ~
* }" s, {5 n3 J# M( L
& K0 y% G, r- U7 A
4.CSS阶梯样式边框. A7 }5 f5 D: W8 ^, v+ i& M
CSS代码:4 [& }/ u9 G+ D1 @( V1 e
#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
} 效果如下:
+ x2 N0 j" Y& }% t* Q
5 W$ O7 o: D; {* Z
( Q$ E% | U/ n5.CSS只有阴影边框
2 e; B) ]- a2 t: j- v$ N& zCSS代码:/ W. W9 F5 s6 d3 N& H6 k
#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 @* q1 `" t/ W0 V _9 n
" M7 o6 W" o% O7 q0 _1 a
, ^4 O% w& I" v! t0 j/ A, m6 K& q6.CSS带阴影和轮廓的边框1 y# Y& y4 Q5 M( c! F
CSS代码:
8 P) G3 a: g0 h- s6 S. W# f% H+ i8 W#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;
} 效果如下:
5 Y* q# a9 k4 }, W' z& ~4 i
$ y/ x* i! q; b: ^
. I1 [7 y1 \3 \, \4 [2 u5 s* A7.CSS少量阴影和轮廓的边框
% y3 L6 G) j8 }# oCSS代码:7 S; T/ T! W) H7 |( x7 j
#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;
} 效果如下:
9 T8 v# s' X6 d C. q, @9 j
6 L8 @# O# ?$ c# J8 y
+ U& h- C" [) W
8.CSS带有阴影的双边框, k- c* N- V( i3 N3 L2 a: Z
CSS代码:8 F+ x. W! e( C0 c! p
#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;
} 效果如下:
7 b1 \- c# n$ B
8 u% ?6 {" J5 E' _9 c; d
6 Q# |; f; X" N: s9.CSS多色边框# J, }) F) d/ K+ \& A! F
CSS代码:
2 g+ S6 v7 @; e$ G#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;
} 效果如下:
# N" c/ o3 m% K
|