CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。- c3 ^, ? `( y6 Y0 z* H
以下各特效用的HTML代码相同:
, d8 l5 }/ B7 L: i+ [: m- n<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
6 H2 k- W& l0 W1. CSS动画边框7 a: k/ ?0 \% u
CSS代码:
+ r$ Z; [* V- S* ]5 F. j E1 ^@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;
} 效果如下:
1 Y' p6 Z& o0 H: x* c0 L; p- m
( y% g+ p. g8 y. |; ]+ B" A$ I, \1 r3 {7 q
2. CSS图像边框7 }& z/ t- w9 V6 N: B5 i8 W$ ^
CSS代码:
" r5 K, F; M: P#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 H2 g# k D4 e# d9 T! J
3 _* E2 O; q4 B( q
9 e: {% {0 B7 O; E8 g6 S3.CSS蛇式边框
# k: @7 N5 [1 `# m/ a' Y) jCSS代码:
; O3 }) X2 _; b) Y#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;
} 效果如下:
( g0 ^( Y+ a5 U* U! j, T3 }% p
; g8 y, r6 |$ [$ ~1 @; p
, ?5 Y, K8 u( i: u
4.CSS阶梯样式边框
/ d7 Z% G5 s/ Z. ]1 W5 {# } m6 MCSS代码:( ~+ D5 T, @5 [# |9 G( b- D
#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
} 效果如下:
\9 H: A( H! p4 F1 O
/ I' w: T& `* L! d- S. _9 v2 ^7 l3 B/ G6 P% _* M) N2 D
5.CSS只有阴影边框; U+ V% f! `5 N9 n w4 @; s
CSS代码:
% s7 n( z- s5 A2 m5 V* _/ d#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
! Y$ p) T* t" \6 p0 z! q5 Z
: [4 r' g* f1 k O2 n
% A6 Y& F w- y; T+ X# h" O
6.CSS带阴影和轮廓的边框
* b1 ^* _/ S4 t- [# m$ ZCSS代码:
) S* h* A0 `* N: Y$ I6 J8 Y& h#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;
} 效果如下:
5 ~ J+ F2 t: P5 ?% i6 ?& _
- C+ m. V- ^, b* ?) D9 V. F
/ \2 A* P; V9 e& G& h, n1 D0 ~4 T4 h
7.CSS少量阴影和轮廓的边框
' S! Z1 p6 z! n/ l& {8 u8 SCSS代码:
' z) O' C N! p1 e: e" }+ 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;
} 效果如下:
% k5 G6 X9 \% C
4 O2 _: ~( _' r, H4 N
" r8 c N/ w; C0 h6 Y3 A8.CSS带有阴影的双边框
6 l5 ^, U: ^9 D4 P) f8 s6 u' [: k3 ]CSS代码:
0 Z4 Z' `4 D2 |' K4 \#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" [* r5 H4 Q( {& u6 \" |3 K
' s K/ a+ p& u( K
+ p, @+ G7 g& @- X+ `* P" l9.CSS多色边框
2 w' L) _3 u3 B5 {CSS代码:
" w# ~) D4 v3 o* a#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;
} 效果如下:
! x4 v" ]2 c* S' Z+ n- V) b
|