CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
4 }# x; ]5 ^- |5 I, b8 Q 以下各特效用的HTML代码相同:; i* ?: R3 |0 r. \& y. d
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
" `0 @( S3 E+ |$ L1. CSS动画边框
) k9 t) W) k! q( o! oCSS代码:
: ? d+ O, g1 u5 O& w, 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;
} 效果如下:
; }6 V& C6 w/ N% V; ]& {
) R. G7 g. Z6 ^# d' o" G$ B$ b& X3 ^
2. CSS图像边框. W; a8 f, Q& D( m" y
CSS代码:
' N% J9 ]& d. A: x7 ^/ b" ]#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;
} 效果如下:
7 {: h3 K. { K, t3 W# x* K
1 n9 c' P2 |6 i% w3 A7 n7 W
8 Z' j/ P% d% m" O/ E3.CSS蛇式边框1 T( x0 n; |! m/ K3 ~5 c$ v; l
CSS代码:
/ e! n' Z p6 K#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;
} 效果如下:
3 z: ~! Z: V: V6 o
; b% w5 l% p8 m6 U, u, d
+ d5 M. `5 m6 q. H1 @* _+ ^/ I4.CSS阶梯样式边框' V/ R* ]9 V. b3 r
CSS代码:, o0 l- X+ Z! O4 o8 f. r3 x
#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
} 效果如下:
" a4 r) F3 W; Q6 H1 J
) Z0 X! j) B7 b
3 O8 w% O4 Z* u5.CSS只有阴影边框# _( _; q% {4 G; T+ v
CSS代码:
& [% H$ q6 q0 f! P#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 l* P* J3 ~, k- H! j
, a$ m0 V% k! N4 N. N; O: y
% v9 e& M4 t& E& o `
6.CSS带阴影和轮廓的边框
' e+ L, o& d2 H+ k! [CSS代码:
+ I1 l( [3 c" ^. 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;
} 效果如下:
% d- }+ j8 [5 R
4 {8 w% C6 L# U, g! E- k- p
" \4 k. ~* `0 f7.CSS少量阴影和轮廓的边框6 U) C, m P' P' i" {4 U3 r, y
CSS代码:
3 v8 W' i6 @ n0 D#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;
} 效果如下:
* Q/ D* @& Y& P4 \% j
8 f% e# R+ H7 y; @" Q
$ W- D3 Z; n7 @3 _
8.CSS带有阴影的双边框6 h, ]0 p4 k0 h7 |+ s' y n
CSS代码:
3 z1 e4 M; R+ ?, _, L5 ?#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;
} 效果如下:" j" n* r' ^3 g! R3 V2 Z
! R1 K: t. T8 Y& ?9 }# V$ T9 p2 q& Y; `* F! |
9.CSS多色边框8 L/ C/ u9 D, D L( G3 Z+ z4 v
CSS代码:
# q/ e9 m2 N8 g#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;
} 效果如下:
! H A( N% l- R r& X9 p; e6 [9 j
|