CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
+ C, l4 U# V/ Q. o( K5 ~, g( G( Y. I 以下各特效用的HTML代码相同:* [. |( _( U& F# S1 L6 B2 y! G5 F9 U
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> . {) f4 X$ @. U" I* u# Y7 d' U, a' Z
1. CSS动画边框+ H& ~: q/ Y0 m7 z# w
CSS代码:
& o p: \& r$ P3 M4 s9 ^9 |@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;
} 效果如下:" \7 q3 v2 i" D6 ~( d9 [
. {% H; }/ D, t9 ^* q
1 N2 c3 h- ]% y# k+ ?9 Q
2. CSS图像边框$ H. x4 w5 G' v3 K7 y" v6 O
CSS代码:
& B+ x$ g* L0 _6 z. M#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;
} 效果如下:
" S5 l. c7 z% F% }( ?5 j6 P
9 |4 q% u/ f9 g% [/ m% t
, k3 S* u. F4 S" Z+ {3 p6 Y1 H9 E
3.CSS蛇式边框
: N1 Q4 \: _9 ^0 RCSS代码:
K/ ` x! }( G( a) O#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;
} 效果如下:
1 g# y3 G& B2 H0 W( V; e
$ P+ _5 z5 |* X! g) n, s' ~# |1 D7 K+ Z
4.CSS阶梯样式边框
5 q( @- [3 @* Z7 a# m& e. iCSS代码:
o& l( x6 X9 v6 p+ N3 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
} 效果如下:
8 o: G2 Q& l* R5 `" p9 X4 q4 V
2 o' y( A" c! ?1 D( d; @; Y* [$ D/ }$ I' X' F0 U+ B0 v
5.CSS只有阴影边框
3 Y% q/ }+ f3 e/ p1 N+ BCSS代码:) i! C; \% ~$ r& Q& o
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
& N4 z/ l/ @* h& j% {
9 \$ K& `4 k: f' w$ i% Y
3 z9 q j4 r s" N6 b. ~3 Y6.CSS带阴影和轮廓的边框9 j! o. h, G8 V: w% m0 i7 ?
CSS代码: Z9 e9 {! d' `- @; V8 Z
#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;
} 效果如下:% u* n0 v& e4 j
, z) d0 M2 R9 T* b7 q5 v
! z- b; @! r: Q6 N7 `5 k3 z M/ [7.CSS少量阴影和轮廓的边框
; N; w% P9 g. p" {CSS代码:
w) M( {9 s- A$ s6 P! R$ u#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;
} 效果如下:' L4 k! N& ~: j1 Z5 a
% j! {& _2 L2 Z& o( P9 E" J1 o2 }7 t, J
8.CSS带有阴影的双边框
+ P! z$ A, S( O# cCSS代码:
0 b& K' F* X: t4 H4 f9 R#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 ]1 R; O$ P& \# k5 z- `" _9 l) n
: F, r7 I) ?1 y# a8 f; p' H a! j) U# ?9 p+ m& K
9.CSS多色边框! L( w4 O# P( R; }
CSS代码:4 C" I8 ~8 U* V$ a
#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;
} 效果如下:
7 H: f+ U4 }6 c. \4 \- i
|