CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
2 t# ?+ A+ c9 ^0 ^4 ]. R 以下各特效用的HTML代码相同:9 R4 U: E, a% S$ F/ d
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
* Z( x, m2 d8 i( R- p! ?9 W1. CSS动画边框
' n& m6 h0 a! [7 j3 k: }! q+ ]CSS代码:
) D8 w1 J; x/ P7 Z3 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;
} 效果如下:7 _" I% \- {3 X' e
! m6 K, [ O2 s
9 m+ Q* Z) ]7 B3 U2 B
2. CSS图像边框" ^% A/ x2 W' P: O
CSS代码:
% p- G( h. M% l/ y$ Y- q$ k#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 Q7 p0 M6 A4 B" [8 v# o1 [' a
" Y1 C, A1 J6 I2 g# x0 p. _/ h B, v( i6 }3 Z; O H: N( U. f% c% D
3.CSS蛇式边框; K- F0 G: `! c1 w7 A' h
CSS代码:
0 `% Z! w1 g. M9 [' w% b! P#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" G0 h( a; b4 `+ y
3 r5 ]9 ]* s3 M3 p( N, C% A
& `2 H4 P6 e) \4.CSS阶梯样式边框
. J. i" j0 z) p* z+ b& VCSS代码:
$ C0 i3 z; a9 X3 X6 D4 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
} 效果如下:' ~, U6 m/ z" A7 y9 _+ |8 T
( Z, h# ]. i+ j( ]
/ D8 F! a, Q' | Q5.CSS只有阴影边框
* R5 _5 g! `% s# |5 YCSS代码:
' c. L2 f& V, f: X#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
% W1 M# F4 h+ s3 Z4 C, ]% ^$ J- y2 E
8 w3 O% R) D& K
/ k- S0 z# u7 R; R* M: N6.CSS带阴影和轮廓的边框2 ^" P/ D( \# K5 f7 o6 T7 F
CSS代码:$ Q4 n# E- f5 k, V
#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;
} 效果如下:6 M) O+ A8 D; W8 L" L
% M" Y5 X0 _! F: F3 R
' s }! q' C& J7.CSS少量阴影和轮廓的边框
/ `. i7 M& p# y; f; H& MCSS代码:
% J; P3 M* Y! Z0 s" N+ r#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;
} 效果如下:
9 A$ G# T- Y$ w1 M S1 y+ `
; G: L+ ^( M, ~' K* _! V
. u# Y5 {' I' @* H4 U8.CSS带有阴影的双边框 x$ e* o( j4 E" h* s9 a4 L% Q0 E
CSS代码:
/ x+ @6 r: O: S7 O. E#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;
} 效果如下:
* t8 O/ Y4 j V! y! R% A
& l" A+ |* H) O7 a; S3 A) u4 b( Q s- }2 O5 \. a c1 T
9.CSS多色边框; Q* p! i( o9 h0 M0 u! f
CSS代码:: {4 ^0 s" Z' D8 p
#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;
} 效果如下:; G$ Z$ K0 s9 \* S1 `
|