CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。7 ?: ]4 Z3 h+ Q( I" C
以下各特效用的HTML代码相同:
+ E2 x/ u2 g- s6 s<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> % ~2 f% R& @( |$ _* z, W) l! I
1. CSS动画边框
& u3 B6 A( V3 ?; h! O1 |* y0 Z9 |CSS代码:
$ i+ ]5 k+ o1 P! o0 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;
} 效果如下:
4 `- ]; b8 O7 I4 B% V
: E# E# j. u) K3 q+ K
l; O+ @/ F( G8 a2 {2 c2. CSS图像边框, B, b; B( J* F. v9 }! W
CSS代码:( q% T5 t8 e1 I0 L4 y3 a; p
#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;
} 效果如下:
( k1 t- Z- `% l1 |/ q
! W" j9 l% H9 E9 ^( i1 n' W( ~8 D4 r+ z, x# c& d1 {7 q% N! S) D( ^4 h
3.CSS蛇式边框" ^3 M+ |2 m! m2 g; ?
CSS代码:
/ } D. E9 c& u$ {* }#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;
} 效果如下:
3 S5 I# b- J6 t3 s' V
: X% [ }' X( Q( E7 J
O9 \: d5 o0 |# {1 w0 o0 I
4.CSS阶梯样式边框
3 l) Q$ s s1 D' B& t% HCSS代码:6 F8 U" Q$ ]! `: M9 ?8 S, A
#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
} 效果如下:
% s; l3 }0 h) S# L
, ^ ]+ n: M- Y: d8 I- { X9 ?' ~8 r" B5 T: K3 b. H
5.CSS只有阴影边框3 H, J7 G+ g" V; E
CSS代码:
' H( r1 N; p; K& L# H" z#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:1 R% @. o2 a# G( S. c" r% Y
& \* {$ C f4 u# x1 o
' ?0 Y% f- \* L; M5 A6.CSS带阴影和轮廓的边框
, N# S; r1 E I1 c8 a( v5 z4 ZCSS代码:
K" `% X- @, q. W f#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;
} 效果如下:
, i: F8 |* s0 y: [
: w! ~$ I7 ~% y
1 L# P- Q, h8 P! a0 ?
7.CSS少量阴影和轮廓的边框0 y3 |! y" F, s( p# M e5 }- G
CSS代码:
9 F& [. g( W8 S) L- E+ A8 L# y#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;
} 效果如下:
; S6 d- k+ U/ `& e) ^
+ a6 C1 e9 `' t
3 r' ^ R" I3 a8.CSS带有阴影的双边框) w1 @7 B+ P I7 S
CSS代码:
& r6 u1 M5 O% P8 m2 B9 a, G#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;
} 效果如下:$ j1 x5 l" N/ m2 o, K( O+ G
, ~2 h$ {8 X! c( r/ `! \2 d9 m6 q$ m5 `8 y) c1 _- i7 c
9.CSS多色边框! M C5 ?* ~! }3 q2 z2 @
CSS代码:
/ F' ^; \ F9 z W5 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;
} 效果如下:3 x8 b" S8 p' T* [, Z" m
|