CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
& X- s8 S. b# X: K! ~0 Y4 t5 k 以下各特效用的HTML代码相同:
& t7 U% d4 X) Z8 y<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
( L [# s3 M, q0 W7 } r9 A) D1. CSS动画边框8 K4 z( u* e7 m/ m$ x' H& E
CSS代码:& v5 N8 |& ]# |* N- F3 t8 m. q
@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;
} 效果如下:6 ~1 {; L. w& x% X i5 e
. n8 G0 ~+ P/ Z6 O8 X5 q% S. X
, Q/ [3 ~0 K9 |) ]3 I2. CSS图像边框: |# V& R) m! E0 P$ @
CSS代码:( y* z4 `4 }6 v7 I3 J& e1 ?/ [
#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 v- f1 C, b! Y7 \, }8 R
; y1 h0 a1 l/ o( c% ?4 d ~( \/ \; Z- A0 g
3.CSS蛇式边框
# T; |! T* F: H. J' g3 U0 CCSS代码:/ s6 M3 a% U4 s V) [! a/ D8 d
#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;
} 效果如下:
- m# N |6 \2 @' J
# N7 T9 G* P5 j( ?: S
W2 T [2 Q% J8 ?5 V/ T4.CSS阶梯样式边框/ A/ f/ H: w* E) }' }% m
CSS代码:
4 x3 |2 w5 ?/ ?- r& d- f+ `#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
} 效果如下:6 N' o0 `+ m2 [* K. q
! Z/ z# X) c' q3 q/ J8 n
- `3 V6 \6 I6 i9 r, k
5.CSS只有阴影边框0 L6 d" T. X3 c4 E! x, ^% f& Z8 l2 F
CSS代码:
6 K; q1 G% q3 f# [. m" G#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
9 E% g! W1 b5 ^, W( f$ J( }
% Y! q) ^6 M, L
0 X3 X1 S: a2 T
6.CSS带阴影和轮廓的边框' O, D% ?# B/ B* ^
CSS代码:; Q/ X/ b# i5 ~0 Z. \0 F7 Q( K
#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;
} 效果如下:
+ f. a! t9 o1 _; s$ r+ E4 @; `
! L' t& E& {! r4 d7 P
' e. h. b. I! I5 u' l; Y7.CSS少量阴影和轮廓的边框8 a& V7 U7 s& r" v. V
CSS代码:* D, |; G* h+ d6 C3 o
#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;
} 效果如下:% o5 _$ X( [2 }6 M$ ^; |5 g ]
e2 `+ V3 o7 I' w* F3 r2 ]3 |
b# z( w! ]" n, K
8.CSS带有阴影的双边框
; X5 R7 ^7 t# F+ H3 k& b: FCSS代码:
# S4 S3 s6 y# z% I0 @% Z) `" q#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;
} 效果如下:
; {" L' c0 u" s
/ p+ w1 a$ q- ]# ] l
4 \9 L4 }/ ]0 V8 V
9.CSS多色边框 W4 k8 {9 j# t l7 b% {9 E
CSS代码:
# r' a7 O( m; T+ ^/ ?#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# D5 t9 z8 @5 c ?: C, o( T; M
|