CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
$ ?7 i( ]. @: q. \- n 以下各特效用的HTML代码相同:
0 { b9 f& s( D* W; e3 x( p<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
' q" p( ~) ~( G: i1 v! E! V1. CSS动画边框+ S3 R+ w) T' i2 j" K
CSS代码:6 d @9 ^, F, b6 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;
} 效果如下:
# Z' Z- w- Q" g, ?, I
" M' U9 S& P2 Z# ` h& T: e8 S, i
2. CSS图像边框6 f1 O* ]$ G. X- C
CSS代码:
# D) j, f7 B# x! w m! M, F#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;
} 效果如下:
U ~) C9 I% I/ ]6 L
* `3 v: }5 ~+ Z7 M8 h; j
9 `1 h& D) X$ E- K5 L" V$ V1 e5 ]
3.CSS蛇式边框3 N' j& j Q3 [( N4 J
CSS代码:4 |4 d! J) ?7 @% U- r! Y" g H5 N3 ^5 o
#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;
} 效果如下:
0 K( s$ q) X% \# M3 g; ~) z& E- v
+ p @7 D; C, `7 Y1 K. i. [
2 T4 l p/ D2 h: _4.CSS阶梯样式边框9 R. \$ e7 P0 m# u. X( s
CSS代码:6 L, \* W: @( b+ Z D' L
#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
} 效果如下:
6 R5 D5 z4 B! i# R* @
6 H3 H [+ N, o" _/ L/ k
]( m* ~. X$ |7 z" F/ @1 H5.CSS只有阴影边框* }# h) P: e, Z2 |( t; B# F" U
CSS代码:% V9 B4 x8 G* b1 k% Q( T z! z
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:3 @5 c! ^2 t' m- R
' r- Q2 G! K) R+ i# x G
; k" Z" R/ c- {6 w6 |- V
6.CSS带阴影和轮廓的边框, {5 D: `/ m9 g
CSS代码:8 K, t; d% k4 Z
#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;
} 效果如下:3 q5 z# G b0 E* {/ M* \. G
7 U8 C# k/ I2 i7 T
7 e8 _' k& L7 N0 E7.CSS少量阴影和轮廓的边框
4 h9 u4 N4 n0 u, Q7 Z' A* VCSS代码:
% x8 D: u0 H/ d0 L#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;
} 效果如下:
5 V7 D9 A3 v! K9 u
3 C$ Z5 I) \* ~
# @" m8 |4 n2 w; p& v, }8.CSS带有阴影的双边框) k4 @6 Y8 o- `
CSS代码:
) g* F1 a7 j5 q1 \. _3 S! O" m#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;
} 效果如下:; e* I0 Y- k( O* `
I; q% G+ \0 z! }$ n& b" d
( @ e; v6 h2 Q: j9.CSS多色边框& k1 |4 y6 o. y' Y9 Z
CSS代码:
% [' U, c2 |& R1 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;
} 效果如下:2 H! t: J* _4 y8 n4 |4 N
|