CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
( z1 y- z7 g1 L4 E; e4 \, H! i 以下各特效用的HTML代码相同:2 f; A# U2 }2 |3 n: y3 Y
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 0 F, {' N3 l9 V6 G
1. CSS动画边框& E0 A$ a) G* [1 W( o
CSS代码:
; R6 E+ P" J- _* _, 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;
} 效果如下:3 ]. O2 |% Q9 n* p
: C+ E7 H. q$ Z% V6 _" J0 K
) j, a5 d0 M) W- q8 ?) d# n) V
2. CSS图像边框4 ]6 U: ]6 q0 I4 ]
CSS代码:! X, g: e! ?: L8 y8 m3 U
#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;
} 效果如下:
5 e0 L+ P E; [# \8 N& Q! D$ N6 C
- Z& M' i: Y8 m" t8 \! J+ P' g
# n! } \' U! h0 T [& Y$ ~6 C& A* y3.CSS蛇式边框- n3 `7 V- M, ?
CSS代码:
% G q) `1 h0 b) ~% p% j#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;
} 效果如下:
' Y6 [6 K0 K( Q
3 T3 k/ f3 S ]# I$ K# `
6 ]) m, _7 ^1 P1 g6 Q3 Y5 [
4.CSS阶梯样式边框
: o* U* q; U0 |! l/ T gCSS代码:1 d3 t/ y! q2 d5 g4 }* G5 @
#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
} 效果如下:' k7 P# G n5 G) H9 U
& P+ Q6 O. F( f
* Q# M9 c# Z: g6 q5.CSS只有阴影边框6 }# x# Q6 T( A2 p/ B
CSS代码:+ ?0 }+ g6 O& L/ r
#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 }% K0 |0 w$ @
+ H% j) p! P; l
- A) F3 y) {9 l6.CSS带阴影和轮廓的边框5 Y+ o2 J( g. A: i
CSS代码:
* d. V3 Q; c8 _! @% {, S#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;
} 效果如下:$ P& z% v# ] l+ }! B; l
* H- j/ A, n8 ^9 `) \9 C. E* M8 A c/ Y0 L7 M5 r+ _9 L1 J
7.CSS少量阴影和轮廓的边框4 V: J& A6 c) x6 J1 r" j+ N
CSS代码:
6 j& }* R+ l2 k% V) o* A3 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;
} 效果如下: R7 R" [$ r2 L! R! c! n
^9 h9 q0 }, h% j& g- t3 m
4 Z, W: T5 G+ x* N1 a- \8.CSS带有阴影的双边框8 r- d6 ~4 ?% e8 p2 l7 L* k! l
CSS代码:: G7 v1 R; e4 i/ k! h* 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;
} 效果如下:
' Q' u; K6 u j: C! g# R* G
% i. s# J7 p3 n, W& S% }! j. X! l
" a( o6 `8 q) }" ]) }
9.CSS多色边框
: x" f1 p8 ?( ^" C, @CSS代码:# \ x+ Q- R1 s2 P
#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;
} 效果如下:
5 Q B Z0 y: S( L: b9 R; [+ q8 L
|