CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
& S0 Y! X$ }" z! h9 v1 _ 以下各特效用的HTML代码相同:
2 W3 r0 d( o2 e, E% C# M* L5 A% G<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> ( F1 ~4 l2 P6 k) X* C
1. CSS动画边框
: e+ J7 P1 I! l" v0 ?0 iCSS代码:3 x- {7 m! \% W4 m+ 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;
} 效果如下: v! r) g" v7 r: o" |( |2 u
5 w( s1 I" L* P8 F {0 B% |6 z' |
; [5 }8 o; e$ z, c0 [, _2. CSS图像边框1 r- k# M# c: X4 a. O
CSS代码:
4 f- m b ]1 p3 c9 f+ W#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;
} 效果如下:
( c4 h4 A. f9 w/ o7 @6 q5 r
" ~+ g5 r1 L" M+ Z! l
9 Y1 w: \; @! V. \" d1 [3.CSS蛇式边框" q+ d: G b+ h5 i+ i' K5 G
CSS代码:+ J! {' S% B/ }! O0 ]: N
#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;
} 效果如下:* _$ M* u$ j* m. W. B
1 q" t% \+ T) @7 U; M
4 X; _; [+ p! t- F! t8 h1 q
4.CSS阶梯样式边框
$ r5 C) ^# `. I) E2 ?CSS代码:
; \ K1 M) n$ o e$ ?2 v: D#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
} 效果如下:* @0 G' t; ~' H8 M/ u8 }
' i0 m/ W" W+ k8 k$ y* ^. [# [- c$ y. ^. |; M. \) t
5.CSS只有阴影边框
4 F1 O }9 x% {2 OCSS代码:
5 P& @* ^1 z8 p+ ^#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:$ H: R$ U/ q/ s" F1 w7 G
8 l4 N9 k M- v) _7 E2 h' e+ ^3 \. ]/ j. r4 W. Q& A* q5 n
6.CSS带阴影和轮廓的边框
$ u/ q0 Q$ |- D' |) [* hCSS代码:
$ Z% N/ ^8 V y! @. j#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;
} 效果如下: m2 N, |! u6 w6 b
4 j4 d, c- h( F c! \
& B8 L- s3 k3 O/ L! C [) y
7.CSS少量阴影和轮廓的边框! {0 c0 N2 L& _9 |4 v; U9 ]2 x
CSS代码:- m4 o2 i1 D# A, u' L7 S) S5 o
#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;
} 效果如下:
+ f- i( E6 i, [' j5 a& |
" i5 H l; q& C8 n' v5 C/ q
4 B5 S; c$ y z# x9 e2 A1 Q% r
8.CSS带有阴影的双边框
' m( ?& ^5 i) wCSS代码:7 z6 ]8 p- _+ ` i7 f
#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;
} 效果如下:: I s; h7 {2 Q3 c r
" F5 R& J3 b0 K% q( X
0 I% O. d4 }. M8 t; o+ i- X) [" B9.CSS多色边框
, G! |7 k5 J+ s2 O% DCSS代码:
9 ?4 ]0 B% q. H6 J' s, \#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;
} 效果如下:6 b9 I' J6 {, i2 x# V- z7 m
|