CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。% o1 C# C7 r( H
以下各特效用的HTML代码相同:
+ _/ d9 [- j5 d4 z. z<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 6 C( n" c" C% q5 o4 E
1. CSS动画边框" r' G; H% _, R. J$ c
CSS代码:
4 V, M3 B, u. N! v. V4 O@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;
} 效果如下:" G2 h" @# ~1 f* x( ]
8 ^ D0 b/ ^( S
# @4 Z; r: N% a% U2. CSS图像边框- \* L! H* H) _
CSS代码:
% M P% ? T* Q$ r! L2 d. x f#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 r7 B, f8 K' j; o( y
5 |% ^9 [: f9 ]* B
5 ]* l3 M0 U, H( _( s3.CSS蛇式边框
0 S8 x( G; H% U; }0 ~6 G* aCSS代码:( ~7 {: v+ w. `- N7 w) z6 h
#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;
} 效果如下:6 C7 u1 z5 V8 N0 ?( e7 K
; O( N: g, R, L. ^; c$ B* ~) _8 x1 i) M7 A2 `4 U* Q
4.CSS阶梯样式边框) F" Q' O) `; ] ^1 t
CSS代码:
( Y1 y6 H/ L7 V# p. [# i#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
} 效果如下:
+ d2 @+ ?0 }) H# n+ l; D
& D& Z0 Y2 U0 ]: Q" i, X1 q3 }; g4 X# E X9 q9 Q
5.CSS只有阴影边框
3 C6 \ B; R. E# K& w, z9 wCSS代码:
4 F3 q; F6 c' ]/ c#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
7 @5 V, {( W# q# ^$ w9 x
0 E: X9 h. X2 Q& p: T1 w' r# W
( w' L: O* O. F+ c- p& f. }/ U/ |& v6.CSS带阴影和轮廓的边框* f% j) D* {: W; {8 J( D
CSS代码:& e$ w, Q* t% v G7 `$ ]( ]5 d
#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;
} 效果如下:( o5 X$ Q$ `0 d
- z! h+ u w! r) S
1 s( E9 N( K% ?' z! Z% D
7.CSS少量阴影和轮廓的边框7 C- X- O0 f+ n
CSS代码:
. M1 C( q: s, w: C#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;
} 效果如下:' M! }! C$ ^* N
6 ^1 G3 B( Q; X2 m* ?, }
' X$ `" W1 ?9 K$ x8.CSS带有阴影的双边框
: }& t7 X/ W _# J4 P$ SCSS代码:1 R7 R) b7 w8 R6 J' U2 D$ q# ^5 E
#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 A7 Y% G" k `; e) n4 i! j
7 i! u$ L. ]$ `+ w( K/ O0 N+ m! \! T* }3 m: G) i
9.CSS多色边框
8 t- H6 d* c) m! d' ?" iCSS代码:& ~. h9 z! _, a1 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;
} 效果如下:
, R+ ^8 ^' a2 c, k7 U' B+ z
|