CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
) H: b' J2 [ H 以下各特效用的HTML代码相同:! Q D$ U9 Q' n& L# o( Z) Y
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
' q: j! i/ |! A4 I3 a, G: J8 }1. CSS动画边框
0 F9 [) d: G0 h& A+ P* U- D" wCSS代码:
7 e9 g F. p. h% A@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;
} 效果如下:; B. x$ q, @7 F- A' f" W y
( X4 i8 v* V5 U" N. |
" l. _8 g& U; [$ f+ f4 e2. CSS图像边框
. b/ q. Y4 {# {% R7 ~CSS代码:) P9 `' ?9 V& F4 T( n, F8 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;
} 效果如下:$ q+ d" q6 e8 @" F2 @( o5 N
F! V* `* \9 x, x7 Y1 {% F: f' v/ c
. @+ N; ?' C7 T0 d4 V: i
3.CSS蛇式边框
: O w% x+ q* U- v% X9 ~, dCSS代码:
1 W: [! k- O' ?; k! {8 g, q; v4 R5 q#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;
} 效果如下:
( e/ o7 L! n! A% w( c* m
, R& `; F$ S8 J- e+ V# S
( S0 B$ X0 R+ I' v: p9 g
4.CSS阶梯样式边框
$ E( [, H- U; kCSS代码:. U. T6 n+ ?8 g9 x; t! K
#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
} 效果如下: J& A+ ^4 w+ d$ m
+ }" h+ F1 [% _. q* F. _; X$ B) { D) ?
5.CSS只有阴影边框
8 N, \& f( {3 u' L7 n. QCSS代码:
& M2 s0 r( F& }( Y! L3 T, 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;
} 效果如下:8 r T6 e) Z0 q! e/ |1 }3 u
1 a% ~" j* h) h& @* u* @- i
1 I% o5 v/ y# z: w% \) X
6.CSS带阴影和轮廓的边框
* @( V# c3 z/ Y- i/ ?' D$ UCSS代码:
2 a! Y2 `$ [8 ]( p- K#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;
} 效果如下:; a( e6 t+ p( j9 N- R
* o9 ~+ X* l& t5 [' b* D @4 d- D, K
7.CSS少量阴影和轮廓的边框 B! P e: k4 ?+ T3 s& E7 i' k! @
CSS代码:: r5 K; L: n1 I7 U" ]: w
#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;
} 效果如下:
: K1 E5 d5 j1 U! D2 U$ n
9 d3 D, G6 F5 j7 }: n( D: t
2 J$ L. ~3 v8 Q7 d+ U' j8 l5 b8.CSS带有阴影的双边框
0 W3 h I0 X' q( x# t; ~# S% R; C( pCSS代码:3 d3 r- J3 }% S0 q, s" \. @! m
#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;
} 效果如下:5 b ]8 _. l6 m! E
5 n& ], p l D3 r
3 n2 r/ T6 m) {. `! Q3 s! l5 a& d9.CSS多色边框- F+ E) Q! ^) j4 @: B
CSS代码:
0 T8 Z7 B, D% h( x; {; j; R, C#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 R7 W. l( p. V
|