CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。& M0 d! Y5 Q& Q
以下各特效用的HTML代码相同:* W6 o* X' e- _( \' j/ `
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
& w+ I& I) h) d9 v/ }1. CSS动画边框
- v) w5 N) r$ i' }- }1 T% GCSS代码:$ }) G* h, r1 \
@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 A6 C' ?+ V+ G8 ?8 Z
9 c. t, B- J6 {
s2 C6 Z2 S0 K+ l* f0 `$ }2. CSS图像边框
. c( p( f3 s% }- M1 S" ZCSS代码:) d, y! Y2 |4 D. y/ p/ J5 z
#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 X/ E- ~& g8 @: n
" F0 y- Y' x4 l
( T/ v" S A7 W
3.CSS蛇式边框
; ~- P9 ?* {/ b# G' s7 m+ @/ q% wCSS代码:
9 a7 }: @7 J9 j3 b3 ?#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;
} 效果如下:
, @0 B: e/ I, V+ }% n' \
( E+ Q5 V' ~ h% N Y& d
, H2 k s6 ]. D4.CSS阶梯样式边框
4 J1 }! f" R! p, ACSS代码:
1 m! D* k% t7 {6 `. ^$ 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
} 效果如下:0 g+ W5 w- T# D6 a
( A0 W$ C( v" `) I* a( f& H
# w# f# _- |$ u6 @ f1 ^3 N& C5.CSS只有阴影边框
2 H n7 r+ `& }CSS代码:
2 Z& y' L- ?" ^0 ]( D k9 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;
} 效果如下:* {* j* f- H) p8 K9 e, w( T- Y) L J
3 ?$ q# |7 N& J5 k+ f2 E. K1 z& m
6.CSS带阴影和轮廓的边框) E8 D* P) G& N! a& b! n% G
CSS代码:
3 r& |: S! r+ s( E4 o$ l7 ^#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;
} 效果如下:
# S4 A7 I- Y6 b# _
1 w. b0 M% O0 g9 Z7 }
# m# I( z9 |: T9 J) p/ s7.CSS少量阴影和轮廓的边框
1 f9 r9 a9 d2 b) S& L+ Z9 aCSS代码:
6 C6 K' Z; \& F, P! v+ K#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;
} 效果如下:
. p5 a6 F: l+ K4 K# i0 {
/ P1 F9 ~5 R, Y$ {
2 v0 D/ d. i# y# ]1 e8.CSS带有阴影的双边框9 s) c: t* R0 b, Y# P" u
CSS代码:
" I6 P7 g5 a. L( R2 B, s#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;
} 效果如下:3 |1 L7 r( o$ y9 q
' m+ c7 V" d. j: M
6 h% O& E! ?& K9.CSS多色边框4 x9 B' B6 M8 M6 \
CSS代码:5 g. ^) ?% t& _5 S. n* U2 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;
} 效果如下:; P* G. o" J9 W* r& H
|