CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
$ a! h) b) r7 Q$ X3 k# K! L 以下各特效用的HTML代码相同:
9 b% M& x8 E* W9 m6 p: I' J: A2 ]<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> " O0 R: {/ y+ _: k8 k
1. CSS动画边框
) m! D6 b% d# @7 cCSS代码:
" ^& `- U( z1 Y: m* `@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;
} 效果如下:
9 u1 A% a* o& L- c
7 u1 L9 u7 Q7 [: h* N: S8 e2 v) o
2. CSS图像边框/ P; I% a; W* |6 t8 n3 k- T) q
CSS代码:
/ [) q) Y8 [6 g5 H" Z#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;
} 效果如下:9 z, U+ U4 F9 C/ W: R/ d" J: S. K
0 D- r' [; m9 [* J; K( k
( l+ B& U" a( c' n$ a
3.CSS蛇式边框, k& L5 s2 c U* U8 l% t4 ~
CSS代码:' i n' U8 O8 Z* T& y
#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;
} 效果如下:
$ a; B* Q5 Y4 C: V
% i( A. v" K# O4 j+ P9 ~* O
. S7 M1 a* S2 E1 e7 `, b! Z# {5 e! B
4.CSS阶梯样式边框8 U, V d. F& [4 ?
CSS代码:
4 K0 N: A9 E0 P- X. v( T& j#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
} 效果如下:
& \1 m, K3 w5 e5 W
/ z: f. E6 q" V. Y, a7 R3 j9 S0 p
0 K8 }9 R! M0 e9 S5.CSS只有阴影边框
1 w5 Y: \2 e) [4 p( c8 pCSS代码:3 D. v- M6 b7 q0 g! S8 V! v! i3 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 Z4 ]: v I+ _
, Y H# V, t5 \- Z$ G5 o, g
4 F) {/ V+ z1 L% T% ?$ M# ?4 N6.CSS带阴影和轮廓的边框( ~ C7 j A8 d: J' j
CSS代码:) E }0 O# ^# l: f4 P6 N% b" P( X- T- T
#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;
} 效果如下:
: x5 y* E8 l7 n9 e( L
. y; l% x+ W, i* t$ r5 U4 ?
" y B, @% M+ f- s& p$ D. {7.CSS少量阴影和轮廓的边框* V H- P" G6 w
CSS代码:
4 b4 c) ~8 v+ y( S. l) B, G1 k#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;
} 效果如下:
& |7 O) w8 ~9 r3 v- {
: w" B8 {+ P- A/ ]0 s8 w
" d* Q0 N* c* f, F9 m c+ a6 j8.CSS带有阴影的双边框: K+ R/ I0 P2 M' p) l- j
CSS代码:
, s8 `5 Z9 Q" K( {' S# n2 r#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;
} 效果如下:
% O, N( n$ x# }8 @" b4 l
2 l9 W: S! }% [$ x! [% T1 `" _
7 {2 F4 U3 k+ P% s, W9.CSS多色边框
& M0 p$ a" o+ T% B; JCSS代码:
/ @: Q! x8 ?/ {8 I9 w#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/ D1 S7 V4 N7 V1 d
|