CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
" j5 |. y" w+ N- W1 k, J; E 以下各特效用的HTML代码相同:
/ N3 r0 {& K# D<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> / O3 H$ ~+ D7 K+ \$ Z/ g
1. CSS动画边框
8 e3 a& q- D4 C! B7 aCSS代码:
) H+ _% R2 p& ^3 J4 G; F. f@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;
} 效果如下:) j5 j! e; Q D; h5 p) g& S
) ]* R0 I" T+ |/ w0 b. e+ O4 q# V8 Y" m6 L6 w2 S
2. CSS图像边框
0 m1 Y2 f5 S/ U, oCSS代码:5 S: y' d: x+ U
#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;
} 效果如下:
8 Y2 b: B* t% {/ k$ w' k
3 e7 ^) m3 i2 A6 N. |8 n, p, Y% J: y+ j! U) t, E/ g
3.CSS蛇式边框
! e( U9 p5 p9 c* ?0 cCSS代码:( b9 T7 a9 k0 b$ G- g8 w
#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;
} 效果如下:
4 l3 A: [5 Q) q% d5 j' U
, m0 `' c5 V+ J7 D0 K
+ Z, d, f" Q7 [% X0 ]
4.CSS阶梯样式边框
! }" Z* ?4 Q N! {CSS代码:
: X9 e+ V+ P9 v" c8 C4 ~2 z+ O1 Q8 Y#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
} 效果如下:2 p _% `6 h. i
. N) [# ^/ C5 }( z/ r/ M
. u* x L' p' S5.CSS只有阴影边框/ X* K0 b. E, S, ?3 P( _+ ^; z
CSS代码:
! Y J, z3 j; 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;
} 效果如下:6 b0 Z/ J0 C% q4 d5 R3 ^' u/ Q3 Q/ j
" a; b6 U/ N/ o: u
4 e2 R5 k9 v3 V% _7 X6.CSS带阴影和轮廓的边框: v& C% b1 c& M
CSS代码:
# G) R0 [, h+ l% N+ k* E4 `#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;
} 效果如下:
5 c5 F; K, t0 [% O* ]2 V
1 {& [: |; ?; Z1 q0 ^5 P" A# ?/ ~) Q
, [2 R( @9 g( Z$ p" z" B0 s7.CSS少量阴影和轮廓的边框# b6 m8 T: T9 I! ~2 B' Y5 ~- c9 X
CSS代码:
0 m: @; W, G6 x: W, ^% d#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;
} 效果如下:
8 X# o* W8 `# X, Q1 S
3 P6 @& @1 S( T- I
0 h4 T! G* @* z5 ~7 l
8.CSS带有阴影的双边框
1 v3 v0 y4 k' i CCSS代码:
- P( v' K) T& \6 f, X r, @9 [! R+ g#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;
} 效果如下:
/ M/ e( L( s$ P b: N
( a1 |, }) P; i6 p' V+ p6 B- S
9.CSS多色边框
0 a. O* p1 c5 C9 p% X4 K: `% ACSS代码:$ J/ r5 I0 |7 i" F" 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;
} 效果如下:& ]$ i# E2 [: T$ V
|