CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
0 N9 |3 ^7 e: O9 K& n7 W6 U 以下各特效用的HTML代码相同:, O! d3 I/ Q* n7 m) Q
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 3 |- {! I$ C3 H* o' g4 m; j/ ]
1. CSS动画边框+ ?! N+ c( j% T9 |
CSS代码:
/ z, r5 e. l9 w7 X6 M@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 k9 t( Q" x8 J( x; t+ P
$ L+ q1 @2 u, J4 S' g
' ~0 f D; u. d* B. h+ u h2. CSS图像边框
4 [. L0 e( r$ R K- n: X2 D; ICSS代码:
" o2 W( i& i$ k8 a#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& U( h1 ]7 k/ @( s
' L N, X; T/ Y. t+ W! t+ ?
0 _/ H* E3 c/ L- i, y3.CSS蛇式边框
& g" `4 c2 s; FCSS代码:
2 E5 d6 Q7 T8 M* H# A# B; h#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;
} 效果如下:7 ?- i$ A. |7 c- J: j# Z5 R% l; Q
, ~1 ~' ^+ k% B/ v: ~
8 z- v: R) H% }2 B( y- i& o4.CSS阶梯样式边框2 W6 x' Y" {4 g* x
CSS代码:
$ h, r$ I' G+ q1 I' t# B+ n#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
} 效果如下:
V1 p3 K' J: e" {
" `: ~$ _6 ~+ k
2 z0 t( T# z# c' e9 w
5.CSS只有阴影边框
) f. m; {* v- iCSS代码:& X3 R& p. J. C* 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;
} 效果如下:. P6 d' [8 o. R) a6 _% Q9 ]
# H# E: R/ C0 L- a5 E
9 G& G5 N1 A3 ?0 |/ j* F+ ~$ X
6.CSS带阴影和轮廓的边框9 r R% R& A3 I- B2 | {5 n( q
CSS代码:3 p2 L! w6 z. Y7 y7 k6 |
#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;
} 效果如下:9 V* {- D: `' G9 E/ A
; |$ ]$ t Q* b7 v* H5 L( |6 |0 P* W/ H0 r& ^1 x
7.CSS少量阴影和轮廓的边框4 }# U: g; l7 L% |3 N
CSS代码:
0 H/ I5 C2 ?# T/ W2 i#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 D: i& f# S' W' r& H) d
' e2 ?/ V1 [4 }$ F
+ Q# n7 s s$ v; [% a8.CSS带有阴影的双边框
/ g% R( H% W2 w0 u7 u" t) E6 LCSS代码:* ^7 i$ T6 |% e) i% r7 w
#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;
} 效果如下:
& m; E, K3 _% C/ X
/ M' |0 V& F/ f% p+ \" k- |
( S% W A( Z4 W& a- v/ U' b9.CSS多色边框, R6 j- V2 x( P7 N) V" M! L
CSS代码:
6 {8 @* p" ?) a. r% s' x#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;
} 效果如下:$ d+ @/ K. @9 Y, z& V, q
|