CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。; m' C+ H+ l$ V/ M; {+ o& l
以下各特效用的HTML代码相同:
2 o8 I# k9 w7 a3 n<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
$ o5 f6 K) u4 z1. CSS动画边框
% I3 F) q1 C4 j8 X) JCSS代码:
3 w# o+ R; y: v- e p: U: j8 @/ t@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;
} 效果如下:+ _; j0 f6 P' j$ ]4 f3 Q
; Y8 P0 Q# h) p2 f# Y3 I
' |1 b6 j: Y4 v% h- x9 [1 ]. ^2. CSS图像边框
, ]8 x" P3 B) dCSS代码:' g- w& b1 D6 ~& x! A1 w. x3 k
#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 ? h( ]: h8 e- T7 y0 y0 h
0 P4 Y$ o- y- V* d. x6 D4 d! _, e, O8 _- i; i
3.CSS蛇式边框3 [' y( J) u1 M
CSS代码:0 |3 |! V0 p) a8 a! E3 Z1 Q+ _( \
#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;
} 效果如下:2 A4 d& [8 d" n8 t E
2 e q; M6 m4 G0 C$ A+ g
- ]9 S# J$ I$ Z) b4.CSS阶梯样式边框; l7 e/ ?$ P2 o- K0 a, e; p w
CSS代码:9 @: [' X5 V% d w2 [ e% 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
} 效果如下:. A1 P( {, l* B) G- w+ B$ X$ Y
4 T0 ~3 W( Y- U' g( G. L# H; k, k/ a6 C
5.CSS只有阴影边框
! b' }: D( j; l2 t9 t3 {* _CSS代码:* ~ a, V& r7 i4 H3 C9 X
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:3 o5 b6 J4 }3 G& H6 D% A0 ]5 i
; y9 h) H `- g# D8 o( M1 w( e8 _( G/ p1 h# W' t/ _
6.CSS带阴影和轮廓的边框% G4 w# }1 _$ G! a
CSS代码:
( n6 ~- A* m# 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;
} 效果如下:
$ d: T" q* e* ~
* ^( |1 G8 K* }, Z+ m' u" U) ^% v; a1 X7 L. v/ n
7.CSS少量阴影和轮廓的边框
+ `8 Z+ ]( S8 |: B- f6 r5 dCSS代码:
N. O* j) V8 ?& C0 m( F#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;
} 效果如下:! e3 u- S; l2 p5 D7 a z4 N
7 n& M- H: ] ^4 R
( f5 ^" }: R H4 S/ k- I
8.CSS带有阴影的双边框
, b6 O: M2 [; BCSS代码:
- Z' z3 J! g# E& j; S+ {#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;
} 效果如下:" P; U, A5 {' N# e1 [
S; P3 M0 j- F1 M
$ \: _* R# }5 H" u+ @% X" n
9.CSS多色边框
* a, D/ |& w; y8 J. w) S- vCSS代码:% r$ L! `5 B. g% H
#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;
} 效果如下:
3 u. a. \3 J1 c
|