CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。. E; B5 n) `& n+ \8 {( T% {
以下各特效用的HTML代码相同:
- r8 N ?% h, k1 S. k<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
$ p1 K$ |( k/ n1. CSS动画边框
6 b& a% I6 `4 ?; A- [# xCSS代码:
1 y6 d! q6 w3 p/ m; _' x@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;
} 效果如下:
' }. Q# ?! ^/ L( t* q
8 }+ P/ U4 `; _0 D; v9 U
% N* A. ]; o/ @+ a/ {2. CSS图像边框! K' ]# P- l6 i# x! @
CSS代码:
- g* {5 ?9 f- q#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;
} 效果如下:" |9 |* D5 J. Y1 p# g7 f2 ^6 l
' G8 Z! ~1 ?4 @' N6 A
3 U+ g# S6 G& u+ N8 n3.CSS蛇式边框. T1 R& L, C& L0 |( m9 m" N
CSS代码:5 J% j2 G% A# g6 t0 [* g
#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;
} 效果如下:
* G* l# F/ z- `) u3 T. a
2 s( v& u2 m* @! }$ q
% g$ [' y& `, Y4.CSS阶梯样式边框% q4 i% V. @8 ?% \
CSS代码:8 E, n/ w6 M) m* 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
} 效果如下:
) T4 Q5 G( Y) E9 k7 v
8 d6 u! `0 [ j' @- X! w+ P' U, V
2 s4 \% L) r$ f+ ~. [" O5.CSS只有阴影边框
1 o% M8 i( e! N1 c# gCSS代码:
% w, ^( O& C3 P( a$ f#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下: r, [+ P' F1 V% I6 L/ G
$ M7 W; [* K: C( x4 l/ G. F* Z& I! _# d1 N; U( |
6.CSS带阴影和轮廓的边框' r( _+ |( G9 ?1 l7 @
CSS代码:5 e: U) c/ j |, U+ S B. l
#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;
} 效果如下:
: V/ `! l9 y7 Z6 X
' F& e( \, Y. i! }, u
% f' _3 F! @) B! U3 O8 Z2 z( J( w7.CSS少量阴影和轮廓的边框
4 Z; \3 F2 D/ ]1 |- SCSS代码:
# z0 s# S0 V6 [, g* Z7 m#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;
} 效果如下:
Z8 B6 i: G0 M1 u4 Y
% z$ N! H6 p. T
+ l2 Y+ b3 C) U0 R/ Y8.CSS带有阴影的双边框2 A3 _6 s) x/ C" _) P( [
CSS代码:
. e- Z: V# g$ `. ^: s6 ]. t$ _& B#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;
} 效果如下:
+ G- k$ y! D9 S- _4 t0 V1 F
4 H& O3 o9 L0 \" L7 E( o1 [0 \3 \: u: \4 `7 o+ }) Z5 W* t8 p
9.CSS多色边框
6 p: d3 E* G3 }( `: N& M T* nCSS代码:& c, X% u0 {# I3 T- q+ z
#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;
} 效果如下:' W& \1 g; g1 M% ], F! p
|