CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。 \4 ~! k' L3 J* x3 [
以下各特效用的HTML代码相同:
. ^- K+ u& n. t6 m<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
0 W4 a# k: I6 @- n A# g% ^1. CSS动画边框( r3 B% Z6 ?0 d
CSS代码:
$ ~' Q9 F; G( S@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;
} 效果如下:
7 L+ c& [) Q* c
$ {) p. x' H( i0 \% A' {7 E! o
$ F6 W& n% ?( X. ]2. CSS图像边框
: _5 g9 g( x6 E# PCSS代码:8 o* `$ M$ A+ m' |' ~& m
#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;
} 效果如下:
6 Q) y+ Z6 H6 U9 e
* F. f& [1 O- `. C! I* E# u
) @5 J q( d6 N5 x* T
3.CSS蛇式边框3 u# D, j6 R, o0 a
CSS代码:
! [/ Q* r8 d7 X/ u# F#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;
} 效果如下:
! a: U4 K) Z, D N
7 r: h6 @7 h5 F: g" t0 b5 y. K2 Z1 u" \3 D; A/ l
4.CSS阶梯样式边框3 p) V( k8 {6 s$ h
CSS代码:
s A6 a) k P" V2 ^, Y/ P& {#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
} 效果如下:2 e8 R7 \& M4 V! r3 z2 q
/ S8 q$ j; e# }( n7 d, }& Q' z5 J0 F) @2 x- K9 v
5.CSS只有阴影边框, x# X, I* u0 X
CSS代码:
# U% b- z) A0 q! o0 p2 K#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:) ?( b8 w9 b7 [4 R# g
% m9 g7 A" ]$ R) Q2 {& {
0 {! H) \- j+ `
6.CSS带阴影和轮廓的边框
! o. d0 x" V2 f MCSS代码:
3 E: x% {* `; O- B& O0 r0 K: {#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;
} 效果如下:: I: A4 b0 ]1 [- {# k$ g; Y" U6 S) ~
- S% Z* a& ^5 ]: G# }
5 u: Y) k0 M$ s j! S1 C0 C* k7.CSS少量阴影和轮廓的边框% ^3 S+ P; @% {2 I y6 L5 F. f
CSS代码:+ J( v/ _9 B4 x5 ] f3 u- j
#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;
} 效果如下:9 J, M+ r8 Q7 T. v6 a+ N" w) B
; C) |* q6 {3 d! D1 a
7 B4 A( a( J* ~2 B# X0 I( i! H8.CSS带有阴影的双边框
_/ B8 [6 ~2 ` v; BCSS代码:
; ^% f1 i: |; ^: v$ f: i#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;
} 效果如下:: b) P. A; L J% d
6 e/ \; `7 p6 g" w4 q8 y+ [
3 ~: M9 ?7 {( f5 N9.CSS多色边框
8 F# u F) }( L1 l0 K4 MCSS代码:
& ~3 T3 S' e9 D. v4 d#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;
} 效果如下:
4 _/ u; I. R+ K8 q7 w
|