CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。- `3 D* |5 E' t0 @0 Y+ v
以下各特效用的HTML代码相同:' ~6 D3 _) E2 S S* z8 E/ F/ ~
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
( n& W! s+ A2 v. ?1. CSS动画边框, f' N% {! q. d t5 J. I. w7 ]
CSS代码:! m5 q" q4 U7 e3 i
@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;
} 效果如下:/ ] h- I3 a' a+ _& j
8 d4 M. X1 U3 C4 h6 a& s1 I
7 u5 a! z9 W# I8 m3 b
2. CSS图像边框# p |' A" \$ U5 T6 B4 w$ D) o5 ~
CSS代码:$ a5 L( M# [: s1 N5 l5 M
#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;
} 效果如下:; f. a; G$ s& i1 ?; ~
7 X5 E7 Q/ ^& Q
; r1 E, e) R0 ^3 z) J$ A3.CSS蛇式边框
! x% S' V( y3 v, Y" a( ^CSS代码:
: f( t, l$ D0 c# g. q#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;
} 效果如下:# v9 D) b& G: Z3 f
8 J+ i0 p+ Y! c/ I" G) c4 ]8 K: h; R
3 a3 U7 p6 X% I6 P" ]' ^4.CSS阶梯样式边框7 j' L" Q5 u' e5 O' Q: z. i
CSS代码:
# u5 @8 u' V6 N4 h v. G# ~4 B, S#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
} 效果如下:
% t5 T9 O$ n7 s! x- J, P9 l
' u/ i, S* K2 e
. D0 _/ z+ \9 M6 x2 s5.CSS只有阴影边框
; `3 ^8 P, ^, r9 M" {2 sCSS代码:
/ l7 E' L$ j, R9 k3 ~0 w5 @#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:4 G# t0 a: J, c A+ ^* y
) p* q! a5 q" H4 j2 G. b+ P& Y" z% c! n4 [$ o' u
6.CSS带阴影和轮廓的边框
. k4 o1 {7 r ?3 q# |8 P7 K: zCSS代码:
+ D% \) E9 c R#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;
} 效果如下:( |7 R+ H6 H( M, r7 e& x R
1 @/ t( j$ x3 C% P
. v {: A8 t+ G
7.CSS少量阴影和轮廓的边框$ j* [6 ]# ?' n, v! F
CSS代码:* T9 o* L9 z" _( R# e4 _
#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;
} 效果如下:
! g0 Y+ @5 _0 T+ {1 ]5 Y" z; ~
4 A) ?1 U; j A$ w i
# S) t$ s6 B# p2 Q" b, F8.CSS带有阴影的双边框% [7 M1 O) v! e% u& t7 A
CSS代码:
3 x) E( \8 C% u#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;
} 效果如下:
0 n; J- g% U* {5 X2 Y
- H* h% N! s2 ]
" A/ X7 e- l6 h
9.CSS多色边框
" Y. l) k& F7 s/ e' zCSS代码:
0 a6 v, q. |) C#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;
} 效果如下:
- X0 B1 [( s5 p' @0 m6 v
|