CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。! i; c* d7 t- K' S/ t4 n
以下各特效用的HTML代码相同:
5 Y! A# d" B- ?; f3 A8 P4 S) t<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> . O. v. g! T1 M& x. p; s
1. CSS动画边框) o* `, Y$ {% `8 L) }
CSS代码:9 h* l/ ]/ f) h. \9 I2 Z4 q: C. g% 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;
} 效果如下:
2 [' ^: N0 Q. }4 Y- C3 b2 s# |, y
1 x6 T5 M5 e/ C/ e- G
, r+ G& C" ` {. ?5 n7 f. M9 j
2. CSS图像边框
_1 r ~ x4 P7 A5 r* ]CSS代码:
$ M. `& _: y" T( w+ o) `4 r2 r#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 n+ ~$ c" F' k3 h" {
- s: P0 T! S% a3 i) |8 f0 ^
$ \6 W" H0 ^7 T2 B; g3.CSS蛇式边框
0 w2 f- q, c, t# HCSS代码:) W8 D0 d2 c% n6 D0 x
#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;
} 效果如下:/ P6 }" N8 R0 }/ g8 M5 i h
; O! q F5 z8 g* K8 Y
3 w }5 N1 J! C5 t& O9 c/ e' Z4.CSS阶梯样式边框5 M+ h9 D( d; V0 A0 Q; {' l$ ?
CSS代码:3 Y. n% D) m4 a' l" }# {7 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
} 效果如下:
; f# U" O0 _' u5 D" J% b7 l5 S* }
# h( H% `" ?3 d: @ X" y( _
$ [" s9 i4 H m# z( d! u2 T5.CSS只有阴影边框% H4 }! v9 y' H L- a- b
CSS代码:7 I3 w: E# D2 L2 L- C& E
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:) C! N" `8 ^- k7 M
6 n7 t; ?0 @8 m% r2 x
% E# X6 q$ x/ e/ Q y( l& O" ]
6.CSS带阴影和轮廓的边框
+ @# o x i! s6 ^6 j; TCSS代码:' F1 [" Y; D7 \0 m1 d# z
#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 F% k! ^+ i* _5 x, S- ]* S) _
) D( @8 T) ^! y# w' q! `( A% x% ~
0 N P+ O; W2 m& B9 A- @: S7.CSS少量阴影和轮廓的边框- M# f: u- s* K
CSS代码:
$ w9 _% h/ z6 O" U e9 W' \$ B0 z1 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;
} 效果如下:# F/ z9 A; W, {
9 L5 X/ B7 a0 f1 t
1 t7 F+ c; n% |3 y8.CSS带有阴影的双边框
9 s1 u/ V$ X' T* `( MCSS代码:
7 N8 p& ]! }- F$ _" Q9 M8 q#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;
} 效果如下:2 `, ~ R1 B8 E' ]/ {# B# H$ Z
I, S% t. {* B5 ?" e; m: ^
5 C. C' t8 p- V! [, b: _- F" D% a/ d9.CSS多色边框
$ ?6 m# k" t o J% e3 YCSS代码:
# P1 J1 k9 B" n4 i7 S1 _8 o* ?* g, }#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;
} 效果如下: E' G; J; }4 L5 U2 K. z) `4 a. q/ m
|