CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
. v8 T/ M0 Z! G- U 以下各特效用的HTML代码相同:
, t0 Z% u$ T( |<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> : m8 ?2 ~) H$ L: ~5 r
1. CSS动画边框
9 a: r, q: \0 o( z h! WCSS代码:7 [; \4 D. E5 |- @' V
@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;
} 效果如下:
0 }, X3 I) p9 g s( q
- R! ]6 V. N- Y& k' q
1 v3 Q+ \( L7 }, u8 y
2. CSS图像边框4 \, ?& V* g( [3 ?0 J; t0 c
CSS代码:
5 s: X) [7 V% ^" `3 B#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 ^0 T1 Q( V; D. p
. i3 w8 U, W* ~0 t
$ Z& Y- l4 x& z- ]
3.CSS蛇式边框
0 g& ~9 _) V3 R4 S( rCSS代码:
7 r0 f A' u: E4 d2 I4 e#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;
} 效果如下:
4 ?% o, ]( h% l0 [3 z
. u& M- X* Q% { [4 R* B
3 U) m3 T* l* N: |8 y6 d6 P
4.CSS阶梯样式边框
, o! o8 `/ h* H* N1 JCSS代码:6 K7 I/ g. V% R5 o& l9 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
} 效果如下:8 z+ F! ^+ F! ?8 K6 S- k
7 b/ J# R' ~$ W- j/ |6 n1 i* Q/ Q
+ M8 w5 D* I6 m) c3 B2 I# y
5.CSS只有阴影边框: ~: `# J9 X8 V
CSS代码:6 N D4 D7 m. G1 L+ @' i+ n
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:) Z2 o0 ]* o% M/ ~$ m# X
( ]3 U7 z2 H0 |& z& {0 l- J3 y( E4 G$ C9 ?4 C, u: V
6.CSS带阴影和轮廓的边框7 [* m$ Y6 P) o7 J" } t A
CSS代码:
2 c, D# I: @& U: w/ ]2 i5 T+ B#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;
} 效果如下:' G6 I. _+ A, h1 `; ?% W* e+ a
. u5 k! w( Y* Z& d, ~/ H8 Y/ S
/ [6 m; \# \: I) j$ J# e5 [$ H7.CSS少量阴影和轮廓的边框
9 l! [9 N! W3 F% mCSS代码:
# c4 D* {0 D* t' R# \#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;
} 效果如下:" c2 x% j4 B9 [/ `9 ~7 J! U
: m+ }0 H2 `1 m. i! ?! b( M9 t
1 Z, F. [* z7 v- F$ d8.CSS带有阴影的双边框
- p8 y1 |' n( N& C- vCSS代码:
6 p# y$ }7 u T- w+ q1 o% |#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;
} 效果如下:
$ d' U! i( v6 V
6 Y/ C! V; M! P& _
0 h8 c( I8 E: a f8 _& ^1 N9.CSS多色边框
* ~' J: H4 s' t Z8 BCSS代码:
( K, K* D' U+ G/ {#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;
} 效果如下:9 [9 q+ v' z; m, s9 p5 l
|