CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。0 S& T, G0 w, q( r
以下各特效用的HTML代码相同:" l. y5 h9 C/ k5 H# M# X
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
- e; H2 F3 a7 L$ r. b5 ] l) I1. CSS动画边框& W: C4 H& d J+ Y
CSS代码:) R2 N/ e( I& H1 l/ ~7 ~5 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;
} 效果如下:
5 A* i* t: }! q/ D
1 h) z0 ^7 G: X& y
* A+ P3 L2 |: [) A2. CSS图像边框0 ?/ @ U- G. [9 h1 p* h
CSS代码:
! ]6 m' W# G( N* ~9 A4 _#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;
} 效果如下:
! g. w! n" `* I, \* \
. `1 y. [; j2 v; X5 k8 @
7 O& n( s) [% z; R: q ^* F" {, K
3.CSS蛇式边框
. z2 b3 D8 Z$ p8 G( X& w9 SCSS代码:4 c x: F0 H$ b' n
#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;
} 效果如下:
3 ~) ]% l7 D0 m
8 R# ~, R8 b* u+ A! {. q E) u( x/ N6 n" ?
4.CSS阶梯样式边框' k5 O7 M* R! z, R: z
CSS代码:
2 |3 s9 q$ g `* ~. L$ [#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
} 效果如下:
t2 j8 u( l! v' K- h
$ u6 R5 N) A9 Y6 Y9 ]$ M/ S
6 y- o* v/ G% c% e7 u
5.CSS只有阴影边框
3 V! B8 u2 W$ Y; t! @1 n' L% c! ?CSS代码:
( B. o9 Q, v/ c0 ^#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 G& R6 a) y* ^
8 Z* j( M' O2 Y; v4 \- J
: _, m, }; y$ i, z$ b1 g7 Z
6.CSS带阴影和轮廓的边框% l; E8 e6 b4 E% D0 W2 V- Y" w
CSS代码:. \- u+ G/ `8 x! n# M( V5 T/ n
#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;
} 效果如下:& X: z U- S& W
' z, \" ^3 \! T9 ?
- F I! v" S% c- j/ L7 y1 ~: Z1 w6 V
7.CSS少量阴影和轮廓的边框
# y, W' K6 P* O! y. t" V% CCSS代码:
6 j$ u2 \( T" N+ a; V#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;
} 效果如下:- c% A4 L G) K. t, T: @/ B
) R+ q \* x# ^& G0 z' _: V! e3 Z4 T- p+ b( F" I
8.CSS带有阴影的双边框
2 \) Z2 B2 V1 g* q/ XCSS代码:# Y# Q8 S- T6 {1 z1 Q0 W* h/ q: m( C
#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;
} 效果如下:* V# ~, H+ M8 {6 o* g6 a
. y" i' a3 }, E5 Y3 L' p* b, Q: I% R" L/ C; B8 w
9.CSS多色边框
0 j: M7 T3 `/ Z3 z% E/ H% Y/ l% mCSS代码:4 V4 m; p1 @) U; [7 Z
#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;
} 效果如下:
# |+ o4 A4 K, m9 d$ c" x. ~; A' B% G
|