CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。1 ~6 I! h. X0 L+ |9 s7 i
以下各特效用的HTML代码相同:
$ U2 i/ E) W8 I' V0 [# U<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
* t( F' ^/ x6 Z# Y4 q1. CSS动画边框
6 B/ J" j9 q: _% v( z+ cCSS代码:, V! n- D5 i- O1 U( x
@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;
} 效果如下:) E! H3 @" a; T: k
% a" h2 [6 b" B: T" A
3 X. v8 n: e8 g- h7 C3 ^4 |- U% l
2. CSS图像边框
+ h" F; R5 h; u8 Z6 P6 f3 WCSS代码:: S& j* G3 w* ?: y8 Z% ]. z8 E+ 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;
} 效果如下:: j" P% Q+ i" N/ w. n8 H& X
Q, N2 s! K- l+ j; |# D$ [6 @! y- M8 _% {( c. ^' U$ Y
3.CSS蛇式边框- y6 J5 `. k) }+ l9 }$ H
CSS代码:
4 @4 q1 C( j1 k5 f- ^- ]' T! {& M#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;
} 效果如下:
, Z$ W* B: u7 I, X; Q B; ]# N
: Y' w$ R& W5 T( t: }. q6 v3 g
: I, ]6 X) W) S0 p$ K& z0 O" M4.CSS阶梯样式边框
4 @+ t( E. V. vCSS代码:
/ `- A' b+ @. o. j3 L- B: 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
} 效果如下:
- i! N" y. \ b; ?, W G: L
3 I, |/ l2 J% p+ p5 @/ X J# C; }' _- D
. _9 _4 G6 y3 g$ o! o
5.CSS只有阴影边框
5 l5 `' f. T- K& W: V) r |7 }CSS代码:- e; |% H! I! b0 P5 f0 C! s* ~
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:0 Q a& }1 Y. P X1 n9 K: F
+ V$ B) n4 j2 G0 W2 k) _ @0 P
5 p" Q& ~, m |' a2 Z" e6.CSS带阴影和轮廓的边框6 F' N9 u5 [, D; q9 l
CSS代码:6 {0 j" _/ H3 y+ f. 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;
} 效果如下:, |0 Y/ ~: v2 X4 b( L' ]
3 f; i: I6 Q' d
) P) |4 M) W! ]. A
7.CSS少量阴影和轮廓的边框
' P+ Q1 O5 {7 x8 q Q2 i6 f9 y4 FCSS代码:
. ^5 f" g: U4 o6 C8 p/ i& I' \#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 x4 V8 |( ?8 N
1 |/ M: K. K3 }: h7 b8 Z
/ M: X6 w, a2 |/ V0 v' F/ I8.CSS带有阴影的双边框
5 c: k. P* U( t3 Y/ v( p0 r2 FCSS代码:2 S2 B1 ^4 \! e7 l4 u! e; ^
#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;
} 效果如下:
& k+ c6 L5 V" V/ `; w: d" l7 M
/ v: J% B( A" B3 c' |
4 W R6 {- e5 B2 [ Q
9.CSS多色边框
+ S( s- \0 S" u" I2 ACSS代码:" Q" ~$ X& C) x4 k
#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;
} 效果如下:
2 b/ s$ A0 ^" ?! e( u
|