CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
' y# F" }& |# g2 R5 _( r I2 H. u 以下各特效用的HTML代码相同:, _/ o# `: A* a0 E8 h1 O
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> * l2 L7 w5 v5 a9 c. h
1. CSS动画边框
& R: @, V. v. s- k' E8 r- G- C+ dCSS代码:/ e* ^! L0 ^3 H* {' F+ Q* @
@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 o0 D& A0 @3 ]
0 J3 d6 r3 `' O$ [. Q- _
h, R* z. H7 _9 m Y7 u5 `/ L: L
2. CSS图像边框
- i6 l) h" s* Z3 S: ?; I8 bCSS代码:* g1 R3 o# J4 p) Y
#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;
} 效果如下:
4 k% }! q7 q3 ^7 A
* X Y7 l, Y9 O6 u
) c) n9 H: o1 p$ x. O% ?2 s0 U7 C+ Y3.CSS蛇式边框
. Z* V$ i4 a; U, QCSS代码:
& K* A5 O' C' 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;
} 效果如下:
( `* S' V1 b) j9 X' V- t# @. R
& x$ T# m7 P7 M/ X; H' Y2 |& F9 F& c. c4 I( y
4.CSS阶梯样式边框
5 P" l: s% |5 [' h7 rCSS代码:
( V9 E' Z; H$ E. q ]8 R#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
} 效果如下:
! l; H3 \. s9 O& S9 a# ~
/ {$ x# Q# h1 {! U( q R
. f1 C- d* \$ Q% V5.CSS只有阴影边框# s3 @" `& @2 D2 |9 G
CSS代码:
8 z$ Q. X l! N( \#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
8 U* q0 d$ ^3 Y7 ]8 P: N$ s
6 ~( B! J, h5 u- S( K. R$ S
( @% \% z, d# X5 f$ d1 Y
6.CSS带阴影和轮廓的边框+ \: }& x* ^3 ?6 H
CSS代码:
- z6 o2 o- U$ o# \' k/ T#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;
} 效果如下:
* j0 w g! |8 I/ N1 D- i
. P) \- e E1 K( w1 T& p( L8 D
7 P7 h( P2 J" t9 N6 V0 g' `; E7.CSS少量阴影和轮廓的边框
5 N! h( W t/ ~# O) t9 l6 QCSS代码:
0 E5 m' ^/ B3 M" E: U& @#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' e h! A+ B( q. p* y! M1 w+ U
. _# s3 L' M1 I% Y3 t; E* f
7 A% ^. n# P [6 F) N8.CSS带有阴影的双边框
# c! |5 B$ ^# F# d' uCSS代码:( J3 L% |5 R4 C" ?9 O+ Y" Y
#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;
} 效果如下:' s/ F3 d3 n4 H `, R5 m
0 n' C! h, `6 Y6 }6 h8 G
7 Z5 ?) F7 t2 S$ _9.CSS多色边框- n9 m: O1 K+ n! }8 r* ]7 `7 P
CSS代码:' F5 X! ?! \/ x7 n9 s6 f6 w0 ]8 t
#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;
} 效果如下:
' g9 H6 \5 X: }9 t; C
|