CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。9 |. D" T+ b( A) z2 z
以下各特效用的HTML代码相同:( M$ X0 q2 M* B: Z, G% R; R
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
5 o5 ^/ H- m: ]+ N+ g) V1. CSS动画边框' a4 v* b5 @! W7 \9 s6 I% M. p( ~
CSS代码:
' U1 u- k5 P9 v) C@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 q9 n( B# _% b: B d) Y
0 X) l3 h1 Z1 K- V) T3 p9 c7 y$ ]6 r# w4 T/ N* E/ I( a
2. CSS图像边框 C+ h. s. X& K w
CSS代码:
# p, U3 i4 T9 M; [1 ?) C#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;
} 效果如下:
3 ~! ~9 L. o* c4 F! F
$ V; K4 K( x" F1 L( T' C/ E4 S u0 X" S" h4 p2 F& l6 d2 }
3.CSS蛇式边框6 n/ v1 W" N( V
CSS代码:) Y, Y' ^6 ]$ v7 b
#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;
} 效果如下:
, f9 ?5 \* m/ T. I
8 s0 f' L* V* e" f! y
* s; }4 q4 a9 L8 b, R0 o9 U6 k" ?5 T4.CSS阶梯样式边框) ^8 U% I6 i. U4 ]" r
CSS代码:
h$ S2 w* [* R) F: T, p! L. m#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
} 效果如下: B4 G# N# A6 b( ~3 a
9 Y& E8 X* S# e' H# J3 F# @9 [
* ?7 b1 D0 l, D# M0 q5.CSS只有阴影边框: T3 `6 k! q$ k8 V. E- p
CSS代码:
! a5 X& F" s# U8 N0 {#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
6 q8 o; V& E6 o. R" l2 ~' b5 Z
$ E2 }* K, ]" ^* W- K* k
) ?1 {; c+ G6 x0 X6.CSS带阴影和轮廓的边框- u G6 k. J1 u
CSS代码:
2 Z8 e/ h* K( ^2 q; X5 q% b* X#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;
} 效果如下:
0 Z1 d$ |! t3 q* E
& o, A+ H4 s5 M5 a7 p) D
8 [7 Z0 G4 J1 a7.CSS少量阴影和轮廓的边框5 I1 ~7 m1 w6 b
CSS代码:
8 h. l% u! N/ F( Q! p#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;
} 效果如下:- t9 a! I; Y1 a# q$ R, U
; G! U* i0 @* U S) T: m5 j z
& M% y6 o6 \7 X L8.CSS带有阴影的双边框
& G1 B, G& r/ rCSS代码:
Z% F) g+ ^. \" C' o# g#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;
} 效果如下:
/ E0 l' ~( m( W1 n- |1 E% B
% X- @! ^4 V; I" }' A7 K7 f2 U/ V
9.CSS多色边框
t* {# s m& DCSS代码:0 t" O1 Y* ?% W4 w ?7 d3 Q
#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;
} 效果如下:! m, K* a, m8 T0 S5 ]& j1 }; q9 D, L
|