CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。$ h8 \) s+ j' I9 a2 Q) h
以下各特效用的HTML代码相同:# ~3 C4 ` v5 e- k! g& W+ t9 u, T
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
& g i }' W* C& m/ E, _3 d! Q1. CSS动画边框
* @; i9 k) r5 A) |) j( \" JCSS代码:
, T. N+ y7 W8 F1 [" d@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;
} 效果如下:
; V7 e( g3 S) l* l g% H9 {
% [( K; ~! z" h( Q" W9 v% m/ Z x& l/ U' w
2. CSS图像边框
; ]: C$ Y2 B- ?" \CSS代码:& r* j" C; Y7 Q- U1 m5 U1 C0 n
#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 h% t( s4 u, c# Z
/ X* U+ \' @6 _0 {2 S
* d: b q8 I O% S( l& v ?3.CSS蛇式边框 J& W/ H4 |$ o" N c( v
CSS代码:- P6 Q3 K# [ d0 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;
} 效果如下:5 W8 e9 a H" R2 d- f" r
& q2 {3 k* T% c# Q3 i4 S
3 O- D2 R$ }) x+ H4.CSS阶梯样式边框
( j; `1 ]* w+ n. K; Q: r6 WCSS代码:4 Z; {+ A1 |3 I4 y3 A; e
#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
} 效果如下:1 W) L7 ^! \8 ~. t9 c3 K3 P
4 J" Y4 b R4 Y# @4 @9 D
8 B5 n+ D+ p. I" S5.CSS只有阴影边框
L% K) y- F3 M. j \& a) n$ LCSS代码:4 H: A% q% T- d& D2 d- P
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
' ?- n ^+ w; P. V' z6 T; X& d
3 }( Q, @, H" ?
- J L/ Z+ l* B3 w" m1 l9 b6.CSS带阴影和轮廓的边框
( D2 Q8 ?' Y' H& B: k( Q, G9 |' m4 ?CSS代码:% D2 B+ b$ q7 H [" b: G
#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;
} 效果如下:
& ~! s) S. r* B/ D9 V' w
8 ^9 F0 z5 [! O! N4 X
7 q. r& a+ e) ~/ S
7.CSS少量阴影和轮廓的边框
k# j3 x7 p5 R, ~CSS代码:( E/ F, W$ _1 N
#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;
} 效果如下:$ n) A+ _ k+ A* m3 s" h% Z
. }; w7 y) y2 {4 X. _3 G; s. @8 O' P/ @& s% W: L" t
8.CSS带有阴影的双边框
1 D8 r H8 U2 d+ D+ S$ eCSS代码:7 V& L3 }6 t. U4 D R# r; ]
#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& C2 p8 U% s8 M9 c/ a {
- | W# Z7 B3 n# ]
. j$ |8 ~: p2 U2 w; s3 E/ {9.CSS多色边框- ~# Q, T n, y) _
CSS代码:
+ A. M9 g/ w4 m, G. f#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;
} 效果如下:
( {6 x5 _8 L* E
|