CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
+ I, w% s1 L/ @+ I$ l4 h# b 以下各特效用的HTML代码相同:" X, a" g( _6 ?# W$ G4 `
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> ) _/ B. e' X6 I" l$ ~$ d( t
1. CSS动画边框' k$ L/ D5 U+ y* k. t1 N9 W. P
CSS代码:
4 k" Z z" ?9 C% O! Q8 G! t' ^@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;
} 效果如下:
: P* L' Z/ z1 \9 R# w
% f% g" r7 c1 s4 Q
7 |' r: P. O4 A' K, A: U2. CSS图像边框
9 j3 w% d1 E. @( t+ Y4 c8 ECSS代码:" @) ?2 p- F. O: i5 t
#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 e3 i' a; {7 L# }+ U: d" W
, Z( [" R6 A( q( X
# n. Q4 D. O5 w6 n3.CSS蛇式边框
) p& F; c; e# p6 Z- b; ?4 tCSS代码:
) i- T8 \) Z- g$ W# F#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;
} 效果如下:& w0 z8 V: a7 p7 Y" Z0 z/ F& ^( Y
9 b; T" E# S0 e o
/ L' n# k+ z% @8 `9 J' L
4.CSS阶梯样式边框
7 q% }) k, D( I6 s) m% ?CSS代码:
# t& W B* x 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
} 效果如下:
: ^+ ?$ e% a# C9 m9 i
2 q4 M& G/ g3 Z8 {1 j* j p/ n
; {# `6 A: ?8 s0 V( n* F5.CSS只有阴影边框
# G" r8 k* A; H9 TCSS代码:
. g! ~3 }. q+ S: W. }: m#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下: R4 \6 A. |) F; ?' t1 v
' Z0 c6 C1 }# ~3 P; `
- z g. c+ l0 \$ K6.CSS带阴影和轮廓的边框
: R: K* q! f' j4 i7 ICSS代码:
: ]! G6 u7 i( O1 d( B#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;
} 效果如下:
- ?: D1 p! F5 H$ W; ]
- G$ w7 R8 c( H5 H5 L7 o
( `. A! I: f( ~$ K9 r9 h7.CSS少量阴影和轮廓的边框
, p4 U' x+ }- C c+ H9 C! Q8 V, [CSS代码:
9 D1 o; t0 } x* ?; T3 f#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 d1 n0 I2 H0 i; q
; W9 [: x0 }, p+ u/ c. I, e- B( ?1 O8 y" X; e: _# e& _
8.CSS带有阴影的双边框
! U. }6 _1 h5 s8 p. c6 iCSS代码:- H& h. z/ v9 B' V) b# x* h3 x0 Y' q
#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 V7 Z8 E$ }3 U8 N" P
2 ^: `0 h: m" U4 \! a2 S2 i( ?% {! q/ y: I
9.CSS多色边框# W. w7 M4 d" H$ e
CSS代码:0 \5 Q+ x( r7 \' h5 u, @# p
#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;
} 效果如下:9 Z9 j; W6 S1 m* x
|