CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。! O+ j0 E$ d7 Z8 e; L, N1 q
以下各特效用的HTML代码相同:, e$ w0 D1 r$ q; p7 O5 u1 ]
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> . m- E5 }" S- W6 @( i
1. CSS动画边框
7 [+ w, W5 X: Q* w$ }; J& e2 V$ _CSS代码:
! `* y& R9 S* I$ V3 x@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 }, c: d; }- c0 @' X' W% s
- a6 d6 N) R4 K
0 Y' v; v' P1 P! e/ a4 ?9 Y2. CSS图像边框5 {; x( B& O: Z
CSS代码:
+ r! M% P* o; x) 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;
} 效果如下:
' Y0 ^$ o% ]: ~5 S0 f. l
. _1 I, n7 M2 m' o* e- [7 p5 K W3 X& `
3.CSS蛇式边框
4 j, T6 {/ M( Y0 HCSS代码:
0 w8 X: b8 \* o. F/ g$ n: x4 a3 {* z) ~#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;
} 效果如下:
5 V& x4 A. H! v2 n0 F4 `& [& H
/ N9 b0 r- A3 c, L9 k: F$ R
0 z3 D% p, e4 a8 V
4.CSS阶梯样式边框) D- ?: x6 a4 m- ^
CSS代码:
1 o! e) S* o( W3 A* R% O#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
} 效果如下:
# x+ \- q- f" \. R# b
* d. ~+ \% {- l
, b. ?' D; E# J( C8 q/ s7 j
5.CSS只有阴影边框* ~: \& r8 x, U( Y, v
CSS代码:
' w3 ?2 V1 u. }+ Y! d, E' f4 U$ J6 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;
} 效果如下:
5 ^* o( p( }& T. X8 |
/ t( o' g" o/ O( S. C
& n4 Y/ @% R4 T; I. e
6.CSS带阴影和轮廓的边框, u* v7 |. m0 I' [+ U
CSS代码:# Q; R5 J& `% I! F0 j& w
#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;
} 效果如下:3 n5 C/ i1 P5 P) X7 B3 n
' b$ k9 y0 T3 r' }' [' ^; g2 M$ ~
6 I* }/ @; V3 Q! P: k7 H
7.CSS少量阴影和轮廓的边框
: m+ {+ @5 p. f9 ?0 d MCSS代码:
w/ G4 L1 w5 D# @" i0 n9 P$ n#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& i0 _1 C7 O! n$ B* y5 B! A- n
. h o; U* F! r- d* d! Y& r0 Z/ }) D" {+ W. E- @$ U! Z0 f( L
8.CSS带有阴影的双边框
7 {& k3 v" F$ e* E# @. D6 yCSS代码:$ W0 F# G- d5 s! F7 Y
#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;
} 效果如下:
& \; _. O' O3 R% Y- K
, }) ^ G+ q3 O' J3 |2 Q# u
1 J( y! x! K: F3 b3 I9.CSS多色边框
- s* G# v) _6 [4 \+ {1 HCSS代码:! ~# C3 @7 z9 q( T9 v2 |2 J' r$ f
#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;
} 效果如下:) \: F$ s' P; X8 q, @3 x
|