CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
4 d7 q d$ M9 m- Z# g: Q 以下各特效用的HTML代码相同:5 V. V y7 q/ I8 c* s. I9 w
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> ! _. u- {0 c5 S, G( r
1. CSS动画边框5 L3 l, t' V7 w& S6 p" x7 N
CSS代码:) s. M2 K7 J1 }# S
@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;
} 效果如下:
0 \2 d+ R$ t5 M% O8 R& [
" g3 I$ z6 Y8 ] {$ A+ U, D% j
3 p3 ?: I0 e$ [2. CSS图像边框
( \7 `+ }, D! V5 o+ f) [% NCSS代码:; U3 `* x1 E# 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;
} 效果如下:9 H* m/ y# t- F" _. y6 i- t
8 n6 V# `6 S, A6 ^) `) p1 ]
|+ c+ O' x$ k" m- E3.CSS蛇式边框
- t2 f& F7 U. A& \CSS代码:
# c( G) Q& Z# B#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;
} 效果如下:, Y9 m) f7 Q5 e1 R; W
* ~: L5 T% O8 N- m
% e5 b4 Q" A; B. I. T% F$ r4.CSS阶梯样式边框* L; a0 n" P, j1 J
CSS代码:: R) M* X# q7 m7 y4 A
#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
} 效果如下:# N& n. p7 u# H4 }& R
1 ^7 {# K& \# E4 I
2 b; O( z0 S: W8 V
5.CSS只有阴影边框
1 }1 D1 @2 E8 A) l% QCSS代码:
# p. X1 E: f& v#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
. q5 F! q9 w# {6 e: _2 g1 s
! c5 ~" U$ }% \& ]2 @$ M9 r/ O: u9 B$ J8 N. {$ a1 C* }
6.CSS带阴影和轮廓的边框4 W1 j) Q7 }- q! L. w* [$ o4 n
CSS代码:1 ^' B' j0 F( X
#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;
} 效果如下:0 C* l- I" R! ^$ |
( e* s( V: ?' P. l8 d& K
* n3 F; t' [) k# H) ?1 A* i
7.CSS少量阴影和轮廓的边框
0 S+ g8 j, s! Q" K- YCSS代码:
& J! l$ ?+ {! X+ S/ ?' ?6 X#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;
} 效果如下:
; g" E E% c" F% I* M6 |
7 a/ W. k7 S$ [( Z, n ]
6 c/ V# R1 A2 c" h; K. \2 X# p8.CSS带有阴影的双边框& q O* Y7 O- h/ l% W& M3 n; H
CSS代码:
2 s& d/ b7 S; O8 V#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;
} 效果如下:
$ L" a" `# r. S' d9 v0 e$ F l
+ a8 {7 r4 J, L
: L* d, E# O1 {" E8 p9.CSS多色边框 F) c# c1 S R* g/ g$ x/ S
CSS代码:9 ^7 f! E8 ^- W
#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;
} 效果如下:
0 w* ^* `4 S- D* _4 e9 p
|