CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
3 a1 ]3 q" R: u 以下各特效用的HTML代码相同:
# t( m" p, }) D7 Y' I# ^/ F<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
4 ]7 Z- @- r, {) c0 [+ v7 X1. CSS动画边框+ o) i& j2 t8 L& H
CSS代码:. B) M* h, y( a
@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;
} 效果如下:" H3 c$ L; E5 [9 ]& g2 L, q
2 g, C4 U) Y" t8 m/ U" i8 s3 F) W
( v& J A/ I A- p$ D" T2. CSS图像边框! }% q; M3 f& N/ l' D# n
CSS代码:; H% F5 D% B; C- c; t& T q
#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;
} 效果如下:
, z; B3 N3 T5 d: `5 x: N
+ Q) S+ v5 M5 W# F
, V5 S3 _0 v) j# U& v0 L
3.CSS蛇式边框
- |4 W1 v1 o, H& c5 hCSS代码:" m: B) F9 C; T
#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* H# L: l* J) e7 n) u" p
c& Q$ _- \& K# n) U
: z$ i6 \$ U3 O5 V9 L+ y3 N
4.CSS阶梯样式边框7 w. F+ {& c5 s$ O( ?
CSS代码:) a3 L& _4 G& M
#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
} 效果如下:$ N0 q" k0 ^9 ?& \
+ O9 D3 j, V; |( J
, E* o9 M9 K7 ?5 R& m# m+ R. y5.CSS只有阴影边框
* Z5 ^! P* s3 a5 p5 }% e" U' _CSS代码:
7 P0 K m$ t* K$ W' u& a0 a5 i#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:0 E q7 v8 V" c e
& M$ A4 i- t% U: {0 M; q% J
& u- n( o1 S4 i1 F5 f6.CSS带阴影和轮廓的边框5 e' w+ y- \9 w7 M1 C
CSS代码:
1 N1 V( m- ^1 e#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 o7 M9 y) O' M* r5 R
" t& N% R' r- L* R( t& }) [6 v
. W1 q/ V g5 d2 r) g/ o) D
7.CSS少量阴影和轮廓的边框
0 C# t5 Q# V0 ]# N+ O* K; NCSS代码:$ B0 Q* w- B- S( C6 E/ n
#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;
} 效果如下:$ y* i6 ?0 J' M$ N( R$ m% s
: \1 P W$ { T' m; ~; T
+ h" H$ i5 j" t+ g+ J# v
8.CSS带有阴影的双边框 C" M9 F( f9 t. v# ]2 L
CSS代码:
' p5 E6 n" p$ K6 H, F 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;
} 效果如下:8 x% H8 c+ i2 x. T2 j. `
+ h+ N2 t- g2 ]* d7 J
' d, B0 j7 x0 y2 T7 ?% Z; y4 N9.CSS多色边框
4 }0 u; I$ N% J' zCSS代码:5 G" E, w1 {, ]! ^( f& ]. n
#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;
} 效果如下:
( i: T3 O! S M; Z
|