CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。$ u+ d; Q Y f4 [; h7 G
以下各特效用的HTML代码相同:
2 U- }+ i& [5 Y2 f+ A" E2 ^1 P<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> # @, p+ \5 L6 D; q6 l
1. CSS动画边框
+ d( X9 k3 j! w$ DCSS代码:
& D7 q& \$ i% o+ V@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;
} 效果如下: y: O/ _+ _9 ?% V
5 p* D, y- r: f7 H2 }
2 L- `. J8 x& |) l2. CSS图像边框
) T- k2 O7 ?) D' s" X; |6 l HCSS代码:
# B. X9 b* `3 N1 C* b& l, Q& }0 ]#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;
} 效果如下:. h& Z$ q3 c/ n0 H
; Y" W2 f% u; N' X1 i
* ]& O$ c6 p0 V0 D- X9 I% O3.CSS蛇式边框6 f7 N. Q5 V/ f6 x& R5 P @
CSS代码:* O" [! E1 A' R' N/ v) ^! Z
#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;
} 效果如下:
2 K6 H; p& S3 s- D% _/ V1 [
3 P) t, e( X" F, v+ m7 I2 `5 X {: v7 B- ^4 X
4.CSS阶梯样式边框
+ \0 q+ w b6 J+ }3 ^, `% XCSS代码:
8 V6 S4 k8 [+ 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
} 效果如下:1 {# l$ c# _1 |/ F- O9 m# ]
9 P Z3 e# v3 E: A
y( j+ m; k. ^% Z1 R
5.CSS只有阴影边框
. }$ n, O) G8 Q7 A$ h* x. X# dCSS代码:6 w( i% Y5 `* M; O
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
( u* W; v/ V! o. v( A
: _! O5 w% d& m- S/ Z6 O1 _ N) M0 q* B: [1 Q+ ] k$ g4 b
6.CSS带阴影和轮廓的边框
& w7 }: U8 G9 W$ Q SCSS代码:
" \; h6 g$ s& E& F# u#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;
} 效果如下:: ^! w5 a( N* z
8 ?2 c; w$ W1 T: ~+ t) h
& E4 d9 [# r8 H7 |3 l" I. s
7.CSS少量阴影和轮廓的边框
4 D$ O1 t7 y5 ] m% s# {CSS代码:$ |8 W7 i; U: O8 E( ^
#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 i& A" ], Q g
3 [/ l9 g6 N) {( R, k) G5 ?, z3 x$ Q/ r4 d, v0 A
8.CSS带有阴影的双边框
' ]6 Q9 c% p# W6 d4 k& yCSS代码:
. q% m: M7 r7 {#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;
} 效果如下:
9 p! N A$ X; b, B* O
& J, s, T$ X7 r9 _
& A( ?9 r4 _" Q$ ]1 a& F! P2 [9.CSS多色边框2 m6 D4 h; d. Y7 q5 g% n4 s0 e# `
CSS代码:
. l* M3 F' n0 h! h' G#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;
} 效果如下: w ^3 L+ f5 a# ?% `
|