CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。& H9 D& m2 T! c4 F1 j
以下各特效用的HTML代码相同:
8 a1 ]0 e G3 ~' p% Z" B<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
/ B8 d7 p# x0 I. D$ a3 l8 G1. CSS动画边框
) b4 I* j+ v/ a9 }CSS代码:
; \1 m1 D7 K+ s7 I% Q O. H@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;
} 效果如下:
4 V( m9 r+ G. Y+ k( X$ W
! X0 r ~$ Z- j0 l+ A! f6 v+ d( r0 ~( t5 Q$ u9 B: O
2. CSS图像边框/ }( |4 E6 j) I$ I
CSS代码:9 N! s+ p. {% T, K
#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;
} 效果如下:3 q* T( A% G+ G
O7 s5 A1 P7 @- i
. U* O" ]7 D* N9 ^# i3.CSS蛇式边框
4 r$ j: i: ~' W' ]CSS代码:+ ~( q) \8 v; ?# w
#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;
} 效果如下:
% X+ F1 s3 N, P& K( O0 T- {
! L+ ]# N# {+ D$ L# g& a
! V& [8 C' g. ~- r
4.CSS阶梯样式边框
. S$ ^5 ~ H; k0 @4 l/ aCSS代码:7 p% p* M+ j, }3 O6 [, T# A/ r
#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
} 效果如下:9 k6 d, }; f/ j
1 g6 j$ ^7 F7 }
! v; u% u7 p1 y/ s/ w5.CSS只有阴影边框0 }3 D* B' R; i, p6 ^
CSS代码:$ h6 E9 Y3 y# i* L* H& x
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:9 V' J6 C8 X6 K' A2 B- n. Q
; C0 q2 s2 R! l+ C8 I, K1 I
8 B: w! ~0 [, d- f, R, i; g, G! N- }
6.CSS带阴影和轮廓的边框( f, @2 n5 u! P1 I6 w( q; Y
CSS代码:* S3 ^% r: A+ [7 S
#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;
} 效果如下:6 H7 Q7 t+ G) l( v9 ?8 k
/ f7 X& R" W& A9 X% @( N. }9 h4 G0 C+ \) q. r/ C
7.CSS少量阴影和轮廓的边框% O& o2 g- |' A) H; P0 U: ^
CSS代码:: ?8 p c9 S6 o+ ^8 H# m% E4 u* B
#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;
} 效果如下:3 L& t" E$ w/ H9 c: C
) }0 W9 K; @/ E9 ^: ^% G
0 W. X0 m+ I4 e; ^0 d* l4 l* ]! B
8.CSS带有阴影的双边框
- o/ q' @- W$ n, J5 ]CSS代码:
; S3 H. X a4 S$ Q8 _#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 |1 } F" H0 a. f! z) m* i
$ X- W& d' d) d" ]# t. l5 a% y& q5 E2 I' n$ e
9.CSS多色边框& e9 I; p6 z. s7 x$ ]: z
CSS代码:8 e1 ?; }' {# _5 q0 Z5 f
#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;
} 效果如下:$ U# m6 x0 b4 w/ C' X5 q1 V5 v
|