CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
: o) z( Q* u& P& ~ Z1 F- H+ T 以下各特效用的HTML代码相同:
0 w# _+ v( a9 H8 S' b<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
, |7 k' v3 ~( E5 Q2 J3 Q, U c' M9 G1. CSS动画边框
- ?; |$ x/ I8 f/ mCSS代码:& Q) r, j( ?' i4 @
@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;
} 效果如下:9 q; [ m( @& t, Y7 Y
8 n3 b% V5 B/ ]' E$ s# K' n t5 o/ r
$ ]4 s; o2 b4 @2. CSS图像边框# X K& ?- |' c' u5 G: e7 R8 t* F) g
CSS代码: u' l1 x7 D$ J: x
#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;
} 效果如下:
2 i5 G5 \! a) V1 F9 T1 X& r
3 g5 W H: J4 o0 J/ c* `2 j# |4 o0 A" @0 `) I% T6 f
3.CSS蛇式边框, d' h, b( Z4 f) Z+ ?/ J) z( P+ }
CSS代码:
9 X. T2 M; c5 X& X2 n. K#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;
} 效果如下:
( a3 G2 m$ u5 L8 C5 k
, }% Z$ w" \4 T) b
9 Y! r* b' L+ O. @4.CSS阶梯样式边框$ T& t% q! O- Q* ^
CSS代码:
3 t% Z- H. g! r9 f#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
} 效果如下:
4 r6 N3 d5 s% ?6 m$ K% F' L
1 t/ R) k6 w# q- W
; Y0 P! i5 C' k. E9 `2 m
5.CSS只有阴影边框
8 V7 D6 C+ g" O( u/ q: W3 rCSS代码:6 g' d( l1 q3 \. |2 |, x$ P3 T
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:7 v/ t% D$ M* y( @# `/ N
( P# z0 L1 h0 i
+ a: f0 E+ [4 ~# R8 I6.CSS带阴影和轮廓的边框
7 s) h/ v$ l) L( T2 W/ B* wCSS代码:8 c4 O! r E4 F4 m9 ]/ ~
#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;
} 效果如下:
$ x; z) K! e. [3 T0 g
; {* M# V6 z- K3 W/ W$ y6 |' f# r
7 [8 J/ v. r2 [9 u7.CSS少量阴影和轮廓的边框$ h- d. D% y; E
CSS代码:; g% q9 ~1 Z- F2 Q/ a% `
#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;
} 效果如下:: u! k |5 G) U$ q4 s
" G L0 P3 V. M9 `
$ d/ v; }7 u3 A* O8.CSS带有阴影的双边框5 ]- T4 Q0 n, ~, m7 d9 K
CSS代码:
6 a" n2 z1 v5 d( @. R+ y; X q, t#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;
} 效果如下:
1 _+ Y% K% T% J, j
6 s* p# s. U9 M) t/ _+ E$ L! [" Q/ L* h; Q9 g1 O
9.CSS多色边框, K8 }3 x0 s- b# H; `9 c' u
CSS代码:
4 Y- h& h( N: Q: Y: D( A. x2 D#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;
} 效果如下:
; L4 p, ]- v/ Y/ a9 Y
|