CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。0 y" m/ J7 o. u6 T) } ^. v2 x
以下各特效用的HTML代码相同:, Y2 w! a5 E7 M' T! E; D0 \
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 9 y d( s% ^3 _! ]5 E
1. CSS动画边框8 X4 \+ z* ]6 W/ D; f. U. L% U7 g
CSS代码:
" L2 F' m2 L6 q, U@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;
} 效果如下:
+ j6 }4 y7 k/ a9 k6 d
/ c) s! `% ?+ Q* D) U
. Z# G& Q5 j0 o! J; s1 y2. CSS图像边框
4 ^* s- i( h& t1 Q8 U1 KCSS代码:
* N y- E* g! g7 D$ L#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;
} 效果如下:
4 ?3 X: ^. |( }- r% p! [0 Y& }
8 h. |" W, Y9 T2 p6 K$ Y8 {
1 }7 G+ s& K3 e+ ~1 K" \3.CSS蛇式边框
5 Q* @" j+ p' p" S5 I; x/ |CSS代码:
' ~1 j$ u9 q8 I' O1 v9 q2 e! m& k#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;
} 效果如下:
7 e1 r e7 x1 N9 H h, J. m
2 O; M! @: ?+ ]1 q! v" I7 v
5 o3 f4 d4 N7 R4.CSS阶梯样式边框" B2 }5 g) G3 |/ P
CSS代码:
, w3 b: B" \, h! N( d$ l, p#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
} 效果如下:( @) C2 Q0 K& o/ {
* s- x; g, B. A% r5 j" n. H, [; f: y0 Y# f* ] k# N
5.CSS只有阴影边框
' w1 l/ Q4 F2 g: C6 r- P9 CCSS代码:3 E" i1 I% z* ]( F; t! V
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:$ e7 ^3 _+ x9 b0 L4 A, [7 E" E
/ U8 t# y$ p3 Y" }) E! h- h6 ~$ b, R+ r; d
6.CSS带阴影和轮廓的边框. ~1 S" x& H3 J
CSS代码:% u$ b8 p: g v b6 W c5 R
#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;
} 效果如下:
) }! X$ K3 U& b. { l+ c
* T+ ], H% F7 X6 T+ n/ J
' M4 L2 d/ X+ \) }: X$ X
7.CSS少量阴影和轮廓的边框
( W5 } K7 A; s$ a: g* O" j# S/ j# VCSS代码:
0 P* L c8 W0 m5 \% I2 o5 G#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;
} 效果如下:% p% `) O, F6 v
* D6 D ]. D/ f2 b. q: |6 S
/ r8 T5 |4 G( ?1 t k8.CSS带有阴影的双边框1 b) y+ \2 g8 U4 ]$ Q: {) v
CSS代码:9 {9 W9 E$ b4 @
#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;
} 效果如下:) g6 \* D1 r9 u" s. s. v# E( l
" B5 ~- n9 F! G. {( i4 Q6 K P! \
( T) Z# S. D3 y+ `# L6 w
9.CSS多色边框4 F) }3 R3 l# H+ b8 `7 w. l% }8 d
CSS代码:
5 [4 a5 V# E/ Q1 g) i#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;
} 效果如下:1 i( v% f5 \# B1 I7 D7 L: _
|