CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。0 R4 S* w4 s# ?
以下各特效用的HTML代码相同:) i# g) Z! G9 t# @
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> & F0 a# d% H! Z. e. L
1. CSS动画边框
1 q! q% L3 _+ l# Z( D' T5 nCSS代码:
% x$ @9 t: M& b% @4 H@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;
} 效果如下:
3 I; ^9 f# f" k- \( S: n: y4 S
. P, ` f4 p1 O X. r2 L
1 {+ _$ T4 O; o. g1 R% s8 x
2. CSS图像边框$ S% t+ ?3 p/ j& ~
CSS代码:
) W9 I. I+ p9 J4 i+ d8 k+ Z, `#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;
} 效果如下:
( R6 C) ?2 h8 h9 ~
/ x# i) K4 y" ^# X/ o2 k
. a" h6 H6 }! ^3 }) [7 m2 v# ^3.CSS蛇式边框
/ q- g7 R6 I5 b: @! QCSS代码:
2 g9 Z" E( Q, j. F$ u" K- D#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;
} 效果如下:$ I/ B5 T, b5 d2 I" d
+ e* Z( z$ l& H# k
& @$ r4 W% r) ]7 ` L4.CSS阶梯样式边框
0 M5 ]5 Y& {* Q8 C4 g1 d. B6 i9 {% I+ QCSS代码:
p/ S. `% U, x- O& ]: N#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
} 效果如下:1 y5 Y( q+ g5 E5 \2 Y- C. {
- V! r3 N+ H% B. d
6 h0 O: {9 Z8 d D5.CSS只有阴影边框9 R' o+ p5 X9 F6 x- [ M) g4 o1 Q
CSS代码:
( ~% @& U5 X( L9 S6 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;
} 效果如下:
9 v" |2 E. ?* V
% @; b- b* ~( p( @4 ^# x' n( `, C2 R0 u3 y% k+ g
6.CSS带阴影和轮廓的边框; D0 v# W7 o9 A; \# W! D
CSS代码:
) Z/ N$ s7 |5 Q8 g) v) D#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;
} 效果如下:
9 E* R- Q5 C, D, {9 x' H/ \
# O* D u! r) Z
: J5 Z) |* B7 _; F6 D7.CSS少量阴影和轮廓的边框& z5 E; o; t7 U2 j
CSS代码:
& v' @) Z2 G6 G- U2 M. ?/ ]#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;
} 效果如下:
4 r+ n5 y8 E" T+ ?" s9 @/ g
0 i, z% p/ s) N# T* j7 w; i
6 `! N% B6 f4 Z1 Q; w/ L1 f8.CSS带有阴影的双边框
, M7 n: f$ Q/ @+ \$ |5 K- @CSS代码:. S' m+ O" E. A" J
#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;
} 效果如下:
7 U2 z- ?9 q6 e7 x& F
& C& R, I) I0 F: p3 w# l( l; H7 f) a% k
9.CSS多色边框* z9 X% r% K0 r# o6 u- A ]
CSS代码:- F P$ M) w' B: H
#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;
} 效果如下:; w" n2 a/ s: y6 p& F4 t8 O
|