CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
2 y9 O' Y0 ^! x4 j# H 以下各特效用的HTML代码相同:
. l' J4 p: h7 |% d% u<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> ) b/ ^7 h X- S( q% q
1. CSS动画边框
+ B2 }2 s+ b; j& vCSS代码:5 g3 ~" }7 C- V+ \! i) }1 d
@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;
} 效果如下:
9 }8 g: h) e0 U0 E3 p! u
- e- D4 H; H4 ~6 ^/ u1 I3 k( u2 ~
" s0 q8 l5 ]; ~$ P2. CSS图像边框- _, n2 [$ P7 t) H7 d" d+ U5 q
CSS代码:$ B/ ]9 _, {6 u) F, ]5 @
#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;
} 效果如下:) X+ f) q- h( W4 b+ A
, M. k* W9 A% K- {; v
: ]! m* n$ O) N B8 j6 u! U
3.CSS蛇式边框2 q4 }. Y3 M$ d% v7 H" o# B( s& `
CSS代码:+ Y. d6 n( B/ S5 B
#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;
} 效果如下:
5 I4 _2 p. E5 p' G4 v8 d( `
, I7 X a9 M: j- V R; v9 `
+ {* G) F2 z$ Y5 S B4.CSS阶梯样式边框- T4 ?, [6 e# |, f: T9 V/ k% L4 n/ `
CSS代码:+ {9 @' i" u& ~; v& j
#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
} 效果如下:! N3 G* m. a9 t% {6 v/ z
$ i) }# @/ {( O0 N1 F$ o$ B
$ J/ l( _, y/ o) N$ B
5.CSS只有阴影边框
9 |7 D* q5 F1 h& NCSS代码:* I. k Y0 Y4 B. l
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:) Y4 r7 V; {! @
" F5 q1 Z+ F* v' y% D7 A
* D) l! O- c7 m7 |$ |. i
6.CSS带阴影和轮廓的边框0 e2 V5 H) r0 d% j p) [9 K6 S
CSS代码:
7 x% v, a; d, b# v1 E#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;
} 效果如下:) s9 }# h8 {2 V
: m5 s9 y' Y& d8 |' V
* E& F! D% Y7 T. N9 @7.CSS少量阴影和轮廓的边框
3 s) {/ x9 n3 B9 xCSS代码:
; j( N+ h% F8 D5 z% f: g#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;
} 效果如下:3 _% x3 F" y, M# @8 v
" k% }7 O. q" }0 O
7 y3 Y6 D2 W( q4 P) }2 |, z8.CSS带有阴影的双边框
' O7 t6 l* o7 h* iCSS代码:& Q3 G p$ @- {) k
#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;
} 效果如下:9 p# U: Y+ i0 Q) I8 g# i
7 E. D1 J4 q$ ~5 b
- p# l8 p) u) w, v- P
9.CSS多色边框
8 m7 }' t' [, d: MCSS代码:
0 N9 h, e, S4 M: I4 |$ ~& s' L9 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;
} 效果如下:
" z1 H1 m' Q3 e
|