CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。7 B+ F& C+ E) r1 N: K! T
以下各特效用的HTML代码相同:6 a. b4 [: Y7 F- U" \
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 1 j+ s( `/ j7 ~- V1 n- q& I
1. CSS动画边框' m D# H& j, Q+ w
CSS代码:
& H! X" ^$ E+ C% X) e/ f@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;
} 效果如下:
8 l2 ?! m4 R; l t% u
' L+ o0 d$ T' X; l- o( W }; {' _, P0 ^1 X Z
2. CSS图像边框
; Z# V2 a) C2 h- HCSS代码:
4 \7 g$ W; [' a#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;
} 效果如下:
! v6 I3 |! O0 |" |; r, M# {, @* N, _
4 F8 P; g& n- B7 L; b P% B2 j
1 z9 U2 L* p+ q5 `- M3.CSS蛇式边框
0 w, M6 ^6 M1 l7 o) l$ rCSS代码:
1 Z+ H1 a1 L" B) I#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;
} 效果如下:
( C% G+ U" G. R3 K& J( S
0 u3 u, S& b4 i6 |' h* a, v
$ Q @. Y- j& {& F4.CSS阶梯样式边框
, _/ x( Y: l SCSS代码:
# Q4 L% T1 O3 J5 n& D' R#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
} 效果如下:
0 Y; r- @* ^ {. a& b
2 h! B$ c# d' o
0 u9 z/ l3 \+ e5 H
5.CSS只有阴影边框5 a+ b! O0 c+ @, ^
CSS代码:
) d' a1 d/ G* d, j8 _$ y9 h9 w#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:3 v6 ^# ^2 z: Z. ]' Q
& G. r( { d9 e2 _5 t( _" \! B8 u
6.CSS带阴影和轮廓的边框
% p7 B1 \* V: rCSS代码:5 N: `; P6 X5 j% f0 K4 g: U1 Y1 p
#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;
} 效果如下:
0 e( N: r8 \* Q6 O( P9 n5 n
' x5 N& K" p1 \4 @# C9 O
- c1 S1 N5 A0 e! r" j+ d7.CSS少量阴影和轮廓的边框, X" W2 r; ~ g& v1 T
CSS代码:
- B6 z# X2 u* ?#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;
} 效果如下:1 M8 O4 u6 \4 W$ |( p& L/ F5 U! i
0 ~% d4 A' y3 r7 i6 |7 ]
) o, ^( v: S; `+ z5 u
8.CSS带有阴影的双边框
* w; X# X1 T1 j5 J' _3 u3 b, GCSS代码:
6 S" d1 r4 h% @+ U% 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;
} 效果如下:
0 v! n! U0 I9 n
) z: R% @1 k+ ?% N
) {# t2 `$ Y$ G# F. r
9.CSS多色边框, m) J$ {/ P( I0 A+ f- ~# A w
CSS代码:! \# {( i: X1 P7 X, S0 Z, h
#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;
} 效果如下: C T. W3 z1 c9 O/ p
|