CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。( I, t; b8 p! f2 @( v: a9 F
以下各特效用的HTML代码相同:
* d2 G& K" |; d! n e& i6 S9 Z<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 1 b4 G' {& d P, [& b- H8 s: O* U
1. CSS动画边框
& q" G& t% V. H. \$ G+ {CSS代码:
" U) c1 H4 [7 ?9 _. H; r$ c# ?@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;
} 效果如下:
1 s% |1 r, ^" W2 S/ U+ k
- E" `4 v X M
0 ^0 c+ S" F& _" V7 q2. CSS图像边框" h" O1 t) w7 ], t' H. b
CSS代码:
- O n8 W( p' J# D6 J#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;
} 效果如下:
" [% L6 h! b. K6 n! p+ o I2 K4 E
7 \( o8 j& A4 [
8 G' T1 S1 Z* s, t' I6 r3.CSS蛇式边框, [0 ~$ l7 y7 M; p7 d6 `
CSS代码:8 {) o4 ?' \- J9 O; B+ u
#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;
} 效果如下:9 r( a8 H) `1 n' p0 G
' R4 Y, j; S: Y+ a6 `) q1 H
, P/ P, p# x' K9 }' S6 H
4.CSS阶梯样式边框; n: k+ R1 B# V" }! O
CSS代码:9 r0 X5 ?. J5 z. n+ w! @4 T
#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
} 效果如下:
0 Y" ^, n/ ]7 V9 q9 y, ?
5 x- H9 ~2 \ g f& h
Y5 [7 ~! k& l! ~1 \: F( k: S9 P
5.CSS只有阴影边框
1 U8 U4 M7 o( ^. l% ACSS代码: f; B }1 C$ 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;
} 效果如下:
+ u+ d, f* W" C4 F7 Z
. |0 J/ M9 W! `) N7 Q2 h/ U0 T: W; N' O
6.CSS带阴影和轮廓的边框
; ^- Q, B, o& ZCSS代码:
5 X0 O& t7 C& E- J#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;
} 效果如下:% [- O" A, v8 _- k7 C- h: A3 V4 }
2 I* V7 [: n( F+ Y3 Q2 E
/ Y g7 O8 F+ H7 B7.CSS少量阴影和轮廓的边框+ i7 y% F& I: `& W d3 _* @2 J
CSS代码:. d6 M8 |+ N# `/ n0 b1 \$ ?+ d( `5 I
#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;
} 效果如下:
/ K& s, M4 d& `- y7 B% ?+ ]
% L6 B* m& n1 O g& \
$ d( k8 H6 b% X4 ^8.CSS带有阴影的双边框+ ]& q0 K+ i7 B1 r; ~# R! f6 z( d
CSS代码:* p- [3 [1 }; Z& M
#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;
} 效果如下:
! `3 c$ f, }6 G9 J
/ ^ w8 u# L& t2 J$ h
" V! L0 N& N- _1 J% }6 C9.CSS多色边框) f% ^4 l+ d8 y1 W) i
CSS代码:5 l- W* p! V; J7 h6 C$ l
#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;
} 效果如下:$ r' }0 I L. D6 ^6 h+ L, v
|