CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
. }& J- H6 \2 X: S1 [8 O9 [/ O d 以下各特效用的HTML代码相同: B. {& a! z: h+ p- D3 A
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
7 [1 G8 c/ @: E3 K$ J- ~8 x1. CSS动画边框1 m! @) q% @" S, p" i3 g
CSS代码:) O. ?4 |3 V- X4 e( H& E
@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;
} 效果如下:
4 Z @' t4 r+ z) t. ~0 F7 u$ \
5 ~- Z+ l- ^2 E7 [
4 r7 _( j: b8 W4 e( x
2. CSS图像边框3 Z& A$ V! i M* c& C# @$ K
CSS代码:# o* F: J/ r0 ]3 h' E9 {
#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;
} 效果如下:
, u- E) ]1 v% o. }* e, ^. E# Y: F
2 w" }+ ]$ o: I& X2 k# q- h7 q
, w2 c @. e. |9 ]" y* t) u3.CSS蛇式边框. Z+ H# I$ e7 t6 X; l i) Y. o
CSS代码:8 U6 [3 |1 U/ F1 E! 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;
} 效果如下:
# K8 e& F. J( y5 a- a3 T% B
4 Y# @& B& B. K8 O+ W: r
0 V! v: v) i0 d/ ~* `
4.CSS阶梯样式边框
' R" f5 a9 P$ p, U: X+ UCSS代码:
- u7 l" D( k# b. x) B#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
} 效果如下:9 |* i/ @* m0 q$ _9 Z
! Y ]1 ^* r$ r+ w. v9 A( x4 T* e8 Y. j, Q5 @
5.CSS只有阴影边框
+ C( i9 [. I$ ]0 s: [! Y1 ]# ECSS代码:
) M* m& v; I9 p4 F#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
: w- M* h8 ^/ d' n, ?7 M/ l
0 b4 j* t- X5 Y
+ n: I( ?: ~6 w, |1 c6.CSS带阴影和轮廓的边框, N5 G1 l6 C4 |; z2 @
CSS代码:
0 H% n: Z6 v/ ~$ h4 v8 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;
} 效果如下:
! E2 {8 c% X! P
$ X- l4 H$ ]" g: }
7 ~4 q1 {& p% E( j8 q, i7.CSS少量阴影和轮廓的边框8 C& h# A+ T. f8 n0 l$ Q
CSS代码:* Y( ?& L) z9 A
#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;
} 效果如下:: M4 I$ j3 N# @& q3 R
9 `0 J- n# {8 a( F
, c7 [7 W3 n6 G8.CSS带有阴影的双边框, y% `$ }' p4 g, a: |' U9 B
CSS代码:
& T" }! o/ a# `" s: L' T#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;
} 效果如下:+ Q4 v: i: g5 P7 K5 D2 _
# s# W! g( P. X8 w6 G1 G' V6 I+ j. K/ H9 [
9.CSS多色边框2 o5 s+ q5 E! J: g( P+ J
CSS代码:+ `. j( s6 _+ O& d6 ]
#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;
} 效果如下:
* E( ?5 g% k. P* e# P L( k
|