CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。5 J5 [1 s' v5 b% J
以下各特效用的HTML代码相同:. X7 B g j$ D4 T) V
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 7 Z& ~9 F7 d7 F6 y# F
1. CSS动画边框2 D& U" O& Y+ W' q% w
CSS代码:# {' ^# ~- z# f8 G* M, y
@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;
} 效果如下:0 M: {% N" J3 `5 `6 s
0 I5 ~2 {* s7 x4 @' {" Y' I
; X% U; v+ Q# I3 S, P2. CSS图像边框( U, Z& h i9 T
CSS代码:5 f& Z1 n' z: G# [
#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;
} 效果如下:+ ]( ^! @4 p8 J/ q) x$ A
2 G0 B8 V$ ^9 \( f
, c$ Y5 C3 v7 {' ^ k7 e5 O3.CSS蛇式边框
$ P# E3 Q6 d! TCSS代码:0 S) ], Y8 V5 ?! v9 J/ t) Z
#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;
} 效果如下:
% M. `' j7 Y% D4 L
* |( H' b- r: @+ g) P
/ G) [. y4 |& s+ r% P5 p4.CSS阶梯样式边框
- C* g" X, A% p' a9 _; O# zCSS代码:
! k9 X# Q9 S$ p; ?! u' z#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 ~% D4 s5 r) M; A8 [
% C" A4 Z# H9 p* E6 I, q" N' ^6 O
4 E" w `$ D8 B, s
5.CSS只有阴影边框
5 W- L! ^ D" v4 }CSS代码:' r+ N2 |' A+ J. Y
#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 i* @! Q+ v- `# A C
9 m" [8 T5 \& a/ R% a" S) S
, o# y5 D$ X. ^6 N. X/ H9 s+ d5 r6.CSS带阴影和轮廓的边框
, j! F/ s& m& w9 n, O5 x+ vCSS代码:
6 I( U' x+ p$ N0 s! x, M' q0 {#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;
} 效果如下:
5 o" U0 y) F! r4 C/ s# z
- J6 ^9 n* H2 k% A+ r6 Z/ l4 k; r2 c' X7 ~
7.CSS少量阴影和轮廓的边框
. E* Z& Q' I- _; c/ R. KCSS代码:$ |' Z4 Z9 R) ?- I' s& z
#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;
} 效果如下:
$ R& t8 g0 b2 }- u
: ]$ i) v/ Z! y* w( \, m; H: w8 A" x
8.CSS带有阴影的双边框
; H! ]9 q, N1 e5 `( RCSS代码:
# {8 m2 e1 f2 }7 y/ ~; _#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;
} 效果如下:
0 ]/ Q! |2 t; }
' E' a' v4 ?3 h" p5 @& B( X9 ~
' h" k& `0 { a, D8 K9.CSS多色边框
' Q3 |- ~* D$ Y# zCSS代码:/ C" G- S; ~2 C1 \8 ~
#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;
} 效果如下:) Y' g) B) P8 q9 R( S
|