CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。9 B8 t' ?! K/ a" H, N6 \% G( ~3 b; P( N
以下各特效用的HTML代码相同:: _; t; Q* L& _$ a: v% h9 r2 s! i% c
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 4 p, F5 H$ v+ D2 I, A
1. CSS动画边框5 N/ m7 z0 B3 \! f' x
CSS代码:
3 b# g- i9 R- Q! Q% D2 s6 \@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;
} 效果如下:
3 `/ A' \5 j/ R, c8 ?
( r4 r! d% T! W; ?
* m% X5 g G9 Z+ I2. CSS图像边框
! j O. n! I' l4 ]CSS代码:8 Q6 ~* z6 r3 x j( ?+ s
#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;
} 效果如下:
& ?+ [; O' d5 Q9 U3 k- s
& ?! P1 ?% f( b: ]8 m! L0 \& P" A
$ j- S' b1 y, C% H' p2 E- }3.CSS蛇式边框
# I$ D% v6 B9 F' [# j) }2 _4 WCSS代码:; X H9 @% m6 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;
} 效果如下:
( c" L# L- k$ o3 l9 _. z
: d9 Y- y' n% V7 E
" h' n8 p% }. o" [2 }# R* G8 [2 E3 Q
4.CSS阶梯样式边框3 i0 `' j! A: _. F( A
CSS代码:4 A! r1 R1 `4 N; ]
#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
} 效果如下:
! T1 m5 x4 q7 z/ G
8 ]5 t$ ]4 k+ S
& s6 H* y' {1 h, d3 o5.CSS只有阴影边框, t9 a% p4 j' O: |+ i
CSS代码:
0 {% O) g Q- _" [0 ?! J& w#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:8 j7 z( t- Y9 d- r
# H; c, v0 W, }3 |% k
0 r& W) {1 u6 s8 X6.CSS带阴影和轮廓的边框
; X7 N: [7 Q7 B; tCSS代码:
" M' x6 d* j% i: [#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;
} 效果如下:
2 H0 b1 Z. u8 g# j9 j6 Y/ Z
1 r( V1 a$ R- J; J+ K/ s5 T3 R7 u# W6 a
7.CSS少量阴影和轮廓的边框" v( M% h- \+ W/ C1 e6 } d& f
CSS代码:- J2 N8 Q \4 f9 m q
#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;
} 效果如下:/ x* o& {, S$ I* g5 O$ q
- y3 I6 Y' x$ ~6 _& `3 A
, z: I0 G5 M, C: z2 p) }7 M8.CSS带有阴影的双边框
/ u( o% T8 O( h3 dCSS代码:
" J% w+ r+ G8 H" c9 L/ ]* Y6 L* _3 p# Y; 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;
} 效果如下:
+ f6 V$ e( l7 k# w0 k/ ~
3 v6 P% i4 V/ b' V3 |) L7 x
4 e& r$ K3 Z* e! A0 G* \* G# z1 l" p
9.CSS多色边框
L6 ]& [9 F) ]. E# jCSS代码:
' b2 i; a2 X6 B: m#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;
} 效果如下:
, T: X, r. y/ o( P5 \+ w
|