CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
9 W6 B, e. J$ R. L# V 以下各特效用的HTML代码相同:
$ O" f/ G3 q0 o' T0 U# ]# Z) t<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 3 c$ y/ _% R s/ Y; `8 N$ h& ]1 P
1. CSS动画边框
# o8 d( U- T& b& P. T5 yCSS代码:( l6 J) R- }* O+ ]) e: 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;
} 效果如下:
" }! A: J) \% V! W2 m4 K
7 P h( B0 L+ W% }5 E7 U0 v- f
v; P3 A% G6 e4 J& N2. CSS图像边框
: Q# r, x( ~$ z0 a9 H% X, pCSS代码:
4 O1 ]' h& \- e) Y3 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;
} 效果如下:
7 @; o8 u7 h* T
% |1 Y5 [0 K9 b
8 H) U3 t, _1 v: }2 G" E3 }3.CSS蛇式边框
' M" n% H; [! d4 T0 WCSS代码:
4 Q$ @4 v2 I/ k0 A. e#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;
} 效果如下:
+ J9 I" `; F/ Q2 O( ]
) ?" }3 }" b. R) Z4 n! `+ y* p& g* q, \* I2 o4 ]
4.CSS阶梯样式边框% `9 ~7 p$ D3 }3 r0 u
CSS代码:" s5 C: x5 e& c; i6 [
#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
} 效果如下:
- t/ L7 b2 {& \) Q2 G5 @
7 ?8 V4 M' E; J: R
" I, I+ f1 r% k5.CSS只有阴影边框
6 H. f2 b# x+ b3 x/ _3 JCSS代码:: `$ H' m. }- z: v
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
! Q8 u4 w$ i7 J6 L1 E. a2 F4 q
0 v% G9 P I5 d+ ]! E4 T: G0 c5 V' _9 _1 s/ \9 [9 x8 ^; G
6.CSS带阴影和轮廓的边框
, \. V: u2 m1 OCSS代码:6 ^% `' n8 s; B! 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;
} 效果如下:: g$ I" v/ @4 P! ^' K
1 n% {/ k! Z# ]0 V2 F; G8 _$ B3 I3 {. m4 ?" s; j/ T x
7.CSS少量阴影和轮廓的边框
5 z4 w! N- s3 v$ Q0 F6 `CSS代码:8 b5 } J' q- M7 q" U# E0 H
#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;
} 效果如下:5 _; r4 p! \: f+ f+ M
4 x# [% r3 V X0 x" E7 g' {0 \6 q
9 K+ C; w1 N. h! b1 {" R8.CSS带有阴影的双边框
Q+ p: H! c) |CSS代码:
$ M1 H" c- F! o7 s' ?#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 p3 W& ]' P5 O: n. ~3 D4 F
! P3 S. f8 w7 ]. C8 L7 k$ t q4 `8 |1 n$ k
9.CSS多色边框
8 }% m, j' o0 i2 d, J7 z# ICSS代码:! x3 {+ Q" \+ 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;
} 效果如下:
1 Q$ M: A9 w- _* l! `9 z) S+ y
|