CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
* C! ~, N$ V8 J, G c2 S9 G 以下各特效用的HTML代码相同:
. A' `- O8 T- y' ^4 i<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
( @; [8 _2 G" x" `% f2 S2 R1. CSS动画边框
5 T: ?" t8 u- i ~4 ACSS代码:( O6 I) P; T# 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;
} 效果如下:: p1 H- { k+ s& L; Y3 A/ a/ @0 y
! L# l" [ j6 D" ^4 C% v( z
5 S/ i$ |! m- h* w9 _" s2. CSS图像边框
% r% {, ^4 c$ mCSS代码: z, j. |$ K. C2 K7 B1 Z
#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;
} 效果如下:
2 B3 p* c1 T) D+ r) b; N
5 A* n6 e% G. A& Q1 V/ D. O, _( B4 `2 H& g/ _: i X
3.CSS蛇式边框
6 F0 Q$ a4 Q6 r, a$ QCSS代码:2 E/ p0 V; T+ T* `# X
#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 v# O6 h# Q7 B: ~% [
8 a* i. \/ O0 b7 r0 _
* i4 x: O9 b5 S! b, [; |# ]4.CSS阶梯样式边框
) n3 M+ i: D6 [! iCSS代码: K7 `. \: c" a5 Q% u$ v
#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
} 效果如下:$ D0 M8 t& n( \0 i" y5 j6 V
. p z! ?) G0 j
, |; `1 q1 o6 v3 o( x4 I. U
5.CSS只有阴影边框
# Y# j. ?( w( ~& n7 oCSS代码:
8 E; c4 B# P3 r0 p0 R( t, r9 `#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
6 O( m4 o7 I( c2 {& R6 U
, u! Q+ h9 q: W5 O% y0 N8 J3 I7 G# l6 [
6.CSS带阴影和轮廓的边框9 t; k* e9 v% D$ ^5 w
CSS代码:
( u9 d* a6 N1 z2 T* |3 T4 e#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;
} 效果如下:
3 P6 y3 y0 `; K7 ~( B+ W, C
A$ X7 _$ x( B1 |
/ } F4 U. b7 i8 D7.CSS少量阴影和轮廓的边框8 ? B) B3 q6 _& s5 m# W5 U
CSS代码:
1 c) c' H" m: N' L5 w% r2 j! w2 |' L#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;
} 效果如下:/ k" Y4 o' p) B% i
" i4 B3 u4 B% E+ j7 _# j
% \2 G# P6 \8 o7 o8 |8.CSS带有阴影的双边框& ~ ?& f) m$ Z$ F
CSS代码:
9 [5 g3 Y$ Y1 b7 \ m1 S$ J#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;
} 效果如下:) R K+ ]4 k: |7 @9 f, j
" ?4 c' { h* d9 K
6 U9 C% N b6 _9 r$ a4 d% `9.CSS多色边框$ ]! J6 H5 p+ X/ M1 \
CSS代码:$ @6 O6 q! L, }- E
#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;
} 效果如下:" L! w0 K: L( _& _. G8 W, @
|