CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
7 h# _' p1 l. P8 z! B: C 以下各特效用的HTML代码相同:
, ^& }- x9 f; R. l<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> # d0 R8 w5 X' ` K+ f
1. CSS动画边框
1 M& _( F# m6 ]CSS代码:
2 _ B8 w% D, U- a; T" S$ l@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;
} 效果如下:8 M: |3 C7 i6 D- x
m! ], V$ [ n* b( P+ y2 l
* k+ x; g+ m) @' O* }9 q
2. CSS图像边框( ^' K5 c9 P1 N. v& p
CSS代码:1 s- z# ~) |' U6 J/ H
#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;
} 效果如下:
7 y* J9 ]+ I, F8 _
9 e ~0 g* y- z, ?& o& s& o+ ]9 Y6 I4 O5 M
3.CSS蛇式边框: H' A8 ?4 U- o2 L( t$ q
CSS代码:' h/ G P, J }! g
#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;
} 效果如下:
6 O0 {$ l. H3 H; z* Y3 b
B7 N* q- {7 J& i) L
, F" S! K- Q5 u/ y4.CSS阶梯样式边框
Y4 w# m& q" d* q4 p/ O- a2 n- yCSS代码:
* Y4 R4 e" L6 D' R0 _" 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
} 效果如下:
& E. y! z5 O! \+ O9 Y; z
2 T8 _. r' S0 M- N+ ~
' D# L3 c) J k. }6 ^9 g5.CSS只有阴影边框
" L) M) J& c! H& L& jCSS代码:
$ ~( H: F% A" \' O/ x) K#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
$ g* a6 e) k. t7 [
{$ r5 @/ W# G& |/ o
* _ l, M4 S* h K4 O& |6.CSS带阴影和轮廓的边框
$ I7 L" v, p! sCSS代码:; ?" u6 {4 D( h
#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;
} 效果如下:+ R* V8 n, z1 v" C7 G1 d3 Y
) x3 f4 N: k/ ?
& ?) {% ~) m; L: [ h' w- d: w7.CSS少量阴影和轮廓的边框5 r3 `4 H$ q, X; S' A- p: n: Y
CSS代码:1 f2 l4 e; {+ q! q( s8 N; Y5 a7 x
#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;
} 效果如下:
{# E0 r# `* ]
# d6 ~. s5 n5 g8 p0 x o% f* a# y% n# s9 n7 M3 y$ U
8.CSS带有阴影的双边框
. J- `; Q! x2 t7 WCSS代码:/ D6 T* |$ x7 q C
#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;
} 效果如下:8 a; N- m1 m; C6 C9 d0 j
4 L! [: Y$ P: }! {! O
% T0 A+ G) Z7 o8 m4 N9.CSS多色边框* D: c$ b6 m. C2 }% U( u7 R
CSS代码:
5 X* p0 A% ~$ R#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;
} 效果如下:. P4 c, W; O P1 b5 X) U' E0 Z
|