CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
9 o' d' k3 O" X 以下各特效用的HTML代码相同:
- l+ e! B7 f. n<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> + T4 v- q$ B6 i$ a' q
1. CSS动画边框
8 r: j, d: j; U4 u3 qCSS代码:8 d) ^* T5 W: I& x
@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;
} 效果如下:
( y8 h- f6 T2 E& j& {
; z* m; U" d t0 G) p
* t4 D; q; W1 | L6 U6 I
2. CSS图像边框; {! b* M% l8 ]3 C
CSS代码:" v3 [* z: x3 G2 z8 [' w
#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;
} 效果如下:5 l ]4 [ r6 `
+ o- p( R' Y/ R3 e( J
) o6 ]% [$ i3 r0 ^- X$ D# ?- H% `3.CSS蛇式边框
6 s: F) K5 ?% r7 Q5 T+ ^CSS代码:
7 c) g9 z+ j( G( E1 w) A# D#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;
} 效果如下:
5 g+ y+ B% _8 O2 d
9 f6 s' P0 Z3 @, c
6 V; D5 M f5 s+ t! {4.CSS阶梯样式边框
* b) c( j. P' H v3 c. x3 QCSS代码:
+ L- j* E* j* u7 {- p* s& q: C: z#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
} 效果如下:
' @% R* P# u2 h! J( n8 n
6 s9 a0 f# Q4 K- D9 ^5 c8 L
/ v4 l8 P! K1 j; s* Y7 Q. e
5.CSS只有阴影边框* u# X( u8 O( g; h
CSS代码:2 Z, |/ C1 P6 m# N6 U5 J- `
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:5 Y% j* M, U/ G, u
) N! e4 X5 @' ]/ Q4 |. f7 G% |2 y+ |( S. o
6.CSS带阴影和轮廓的边框
8 y; F3 _1 j! A# P0 @. k5 P! b1 e6 H: BCSS代码:
4 u' d. Y1 X m1 \3 m#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;
} 效果如下:
8 s! I: ]! {: f- G# L' f. O* f# A
$ A0 O- N* r8 r4 E
! t5 c( `# \ {1 p
7.CSS少量阴影和轮廓的边框 b5 U, ^8 \3 e3 h$ \6 W/ `
CSS代码:, \0 V1 E6 U( v$ S$ P" I9 M3 @* o; y, {
#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 l6 c B* R$ B/ M: W' A0 G9 y
# B: j/ K X: M7 P( [3 H$ }& i! Y+ K9 b
8.CSS带有阴影的双边框- o( B# S; `2 N
CSS代码:) y: P$ ?8 e8 \ y$ A. e2 b
#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$ }4 { E' X) ]. o
- m- T, C! c. B$ a8 c. V& M; F3 Z/ k+ t0 p5 |3 C& I
9.CSS多色边框
+ w/ o5 I5 z- [6 S5 UCSS代码:, L9 S# @' v2 m9 X6 E2 \! s @ 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;
} 效果如下:, J6 P' {' q% b! V
|