CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。3 Q5 e" [, B% Z3 M. ~8 P, P9 ?
以下各特效用的HTML代码相同:
4 Q) ]5 I' c% m" M: w( p9 L<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
# I4 \2 U! P+ `$ {6 O2 @8 {$ j q1. CSS动画边框* \) X: i& ^/ J" R; e& @/ G7 e
CSS代码:2 A9 b! I$ |3 b6 M) ^" v; D9 n
@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;
} 效果如下:
4 K3 j4 q9 B( N
$ w3 L0 L5 @: c$ Q9 @; @4 ~
7 Q+ y G# {2 [: S8 H2. CSS图像边框1 s% P2 v" q7 ^* a1 ^
CSS代码:8 z- ]8 m! v! a/ e; 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;
} 效果如下:
|/ l' J) Z6 a1 W' w- Q9 e$ c, L
; n5 o* ^& x' y$ ~% z- @
" P3 i x6 u) E) _5 u2 k- [3.CSS蛇式边框
8 {; a. z9 H5 [: v' G5 xCSS代码:. Z7 `) Y/ z5 @: p* 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;
} 效果如下:% V! L6 K) l/ i
: W4 b0 `6 A' J0 A4 h! {
$ p( h4 g* T6 M9 X+ ~4.CSS阶梯样式边框
6 S4 M" Q1 u6 w; Y7 U" {CSS代码:
/ Y* d( f' M* G# _, G#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
} 效果如下:
" `4 J4 i/ W6 p) [. [1 W7 w
7 }9 R3 m' c% z. J1 [5 ?1 W4 X" C5 g
5.CSS只有阴影边框
5 b& {7 J+ y, ~CSS代码:8 e. B* u c9 \- F% u& h) @
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:' \+ `7 A+ d6 @# a
, ]% x0 e. o Q) W, V
' K9 G1 X& E/ U4 n, P- D% P" j
6.CSS带阴影和轮廓的边框4 v! i' G4 C! M* v7 ~2 M7 e2 R
CSS代码:
9 J9 m) w2 [. n! h, `$ X0 F' P#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;
} 效果如下:. a4 v L+ B- K4 R7 ?* D
& \, f9 b* o8 N7 d+ @0 B* ]& C
# Q* y5 n0 s N* h( n) m$ V- I( o7.CSS少量阴影和轮廓的边框' X& i m e. s0 F" v& |5 h
CSS代码:
' q2 \& Z3 m1 _1 m#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' J4 b' J( C& j0 \
6 L& v8 D, J# H
p N! W9 ]+ b8.CSS带有阴影的双边框
! ?7 t! m, U$ ]CSS代码:
/ O, {0 V; x1 C( V#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 p& |" e( K% d% y- F# V' M
& Y9 s+ D4 d; A6 D) F
7 T4 @9 _: N8 v( n
9.CSS多色边框
q4 S; j$ N, c& k' Q$ ?CSS代码:
m. o! w+ B" @#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;
} 效果如下:( }9 L" O2 {' {* w6 ]
|