CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
( q. B3 v$ {5 x& ^2 c 以下各特效用的HTML代码相同:
g5 F+ ]5 z) w! u% X& n+ |( `<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
3 {1 s" Z. k; Y1. CSS动画边框# n, |) W, }$ u! S0 ~8 M" _
CSS代码:
" d2 e1 ~: w( x! n0 F' W( {@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;
} 效果如下:
8 A) f1 k# f6 s) ~6 q8 W. F: z+ c
/ O, x" d+ i' u# @$ `0 o
' W d- Z- s& ]1 }- \2. CSS图像边框/ q6 ?/ t1 c6 W4 ?: V( x3 D) [6 l4 O
CSS代码:
2 L2 l' ~6 a* w5 `# P#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;
} 效果如下:
1 n5 L @2 H& J! S, X9 I
7 }0 x) c! u7 g+ Q8 l
9 P* v& ^: t1 c; X, y3.CSS蛇式边框
$ q# J" O1 a, m- `% ?0 i8 S) kCSS代码:, _1 C4 c$ D8 J4 P
#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;
} 效果如下:7 d1 Z* p) x: b: w
( k& t3 D* q( O! M" }* d( X2 Q
# i5 ?2 k+ i/ L9 A4.CSS阶梯样式边框
1 ]* S1 c/ }+ T3 N1 c8 ~ S6 j9 YCSS代码:
; s% F- u% m5 G" F/ c$ w#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
} 效果如下:
5 J/ ~$ p f% @
) ?" Z7 }* o, M5 ]+ C
/ G3 F: y8 C$ H9 Y* d7 V
5.CSS只有阴影边框
2 ~! k; |! @( v- p9 @9 DCSS代码:: J t; m2 g( t+ d* d
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
1 w+ M; b* F- |5 O
+ Z" w. {1 t, [8 }+ `
& H3 }& o1 V" Y" h# B7 A1 F
6.CSS带阴影和轮廓的边框
& A7 X( U4 c) C, o7 @8 QCSS代码:5 \4 j# [9 [8 x$ 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;
} 效果如下:: A. q1 y+ W5 z) v
0 p$ s3 o$ j+ ^8 B6 o3 t; z# w- m
" z# O' M3 L' q% e- Z& N y0 _7.CSS少量阴影和轮廓的边框
: j6 L, X6 ~) Z6 ^7 h. @CSS代码:- R; }2 }4 G$ O9 |% P/ \( O# c
#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;
} 效果如下:
* G: j `; |/ b; U3 J4 h
! R: S( B5 E, w) k& ]! _
8 n m# h) E/ w- S7 H8.CSS带有阴影的双边框6 _* o% n2 i! F, G
CSS代码:
0 D g8 P- }9 U& e& P7 R' ^0 ]#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;
} 效果如下:% d5 Z6 E0 I& n m: W( T
& ?" ~, Q4 o _
& O% V% Q3 C1 X3 x' z6 ]
9.CSS多色边框
. T8 U7 b% k# @$ MCSS代码:
+ M$ d$ Z; T+ Y8 u( ^#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;
} 效果如下:# K7 K* \* P% P4 R: X' c! t2 U
|