CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。+ t- ]; w$ j# ?! o" q5 {& _9 W
以下各特效用的HTML代码相同:3 t& H1 H; ~2 c& X
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
; w' y* N: K! n; g3 d5 A1. CSS动画边框
5 j9 g$ Z9 ~/ N0 [0 E! t7 yCSS代码:4 H7 V: f+ H) ~' V; D, P
@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;
} 效果如下:
) d( Q! d# {* A! C$ X0 Q
: ]2 @% t/ ] w2 g/ D( H
+ h2 _1 w9 K& K; q4 N4 i; v9 v# ]) B' B2. CSS图像边框
. V: c: N7 f' m( S. b' CCSS代码:0 B( G6 G/ `' R4 f. K7 W f( ]
#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;
} 效果如下:
, y( f1 O( G# L8 {: X0 B5 x
5 k' e1 i w$ B: V- L& N/ k! N1 C( e) C6 L- ~) Y
3.CSS蛇式边框( Q2 P" c5 g9 R4 ^
CSS代码:( v- I: h+ w/ k- q5 y9 D
#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;
} 效果如下:4 O1 x( [* n2 u( C1 \, i( w7 [- ]
: z. m$ B" {' e8 s- v
9 T! U0 O8 e* Z" d8 \) y4.CSS阶梯样式边框
3 O: A- m/ `6 U' {! n; j7 GCSS代码:
7 h6 k. t5 X+ g Q& m M#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
} 效果如下:
& |* A8 ?6 E# C, x3 R
, q) f9 ?% l+ \( ]5 N1 H9 J0 y3 x d' _
5.CSS只有阴影边框
; O$ s p0 a( ]7 \2 @CSS代码:
# f4 ], o, R/ T; \' C1 j#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
2 A5 j! F) I3 o$ Q
; a. p$ w' e: d' v* j2 y r$ `
( Q* _8 h" |$ T; d- ]
6.CSS带阴影和轮廓的边框+ I! P( l" R. H4 P5 s
CSS代码:- ?0 Z+ Z K8 |2 a
#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;
} 效果如下:
: k! ^- \- J; R; K/ V
0 ^6 }0 B6 i4 D$ |1 C& o+ T6 @% u
7.CSS少量阴影和轮廓的边框
! T# {2 T; b$ |( dCSS代码:' c$ X/ I. a* K0 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;
} 效果如下:4 J1 L" t2 O' w. g: U" t6 w0 U' A! J: E
" `6 z7 J3 Y" ~4 u7 C1 I( z5 N2 Q
0 q$ \( V% T+ I5 s% t
8.CSS带有阴影的双边框5 x1 r& |* u; }" V
CSS代码:
% q4 u% P; L# L/ A% ^# z#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;
} 效果如下:$ ^ L: L8 V5 G0 L% L
4 ^: k! Z& c6 }' C) E
9 l( L! U! X% P- s; ?! J/ s p
9.CSS多色边框: p. ?; x' {+ R- Y
CSS代码:+ ~. g) U4 w' \$ ?% v6 r
#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;
} 效果如下:! Z% e+ r' s( o
|