CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
* @" o! Y; @5 [# k 以下各特效用的HTML代码相同:
+ H% q4 a1 m% ?. R$ m<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 5 h- M8 `5 I i
1. CSS动画边框3 L* ~- T9 B2 D& d4 o' O1 u/ B& T
CSS代码:
# t& c- O J) y* s: 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;
} 效果如下:
' G. q- i5 u5 M; T: ` v4 w" ~
* X7 }2 w% k i' ~. \. A
! k8 Z( w2 f' R4 p$ I
2. CSS图像边框2 z2 ^7 E1 P) p7 a3 R5 X. k- r' h
CSS代码:
# n1 F" G/ z5 @, B! F! C, b1 v#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;
} 效果如下:. S% y' y0 F( K4 ^
$ c7 B5 s' {" K- z& y/ C0 @) b- n7 ]7 W* Q
+ u; a6 A* _/ ^2 G3.CSS蛇式边框
5 F. V& J% s4 }CSS代码:2 n" g9 R! K) b/ H) r
#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; U8 q9 O4 M3 A
6 L, I( C3 U! ^/ M
0 s5 B1 G0 \5 w K+ G; K& i4.CSS阶梯样式边框* ?1 g5 {* w3 A8 I
CSS代码:. z R; V% r+ I! ?9 H
#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
} 效果如下:
' S" J. o2 \4 a# N7 G0 D/ [# n/ Q
- n3 @5 w, N' u
8 t$ l! e& k+ a/ J5 A2 r, N5.CSS只有阴影边框* V5 Z& V. z; @
CSS代码:
" k C9 k9 y0 A- _ D/ s#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:' W- o. m8 Z1 i5 U0 g1 V9 S
* o4 K! U z+ D7 C+ ?
0 [; X' \( B6 K4 r1 k( t+ {: c6.CSS带阴影和轮廓的边框+ F+ W( S' O) q/ K# q+ b
CSS代码:% ^) C: Z- Q- [. |$ f4 F
#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;
} 效果如下:* L9 j# f0 k" t7 g4 e/ a6 A) C, G
. n0 G4 R2 o4 ?5 E; s! n; e. G- ]* J2 D' N s3 d
7.CSS少量阴影和轮廓的边框
& ~( k" J! K5 m: p0 E! @; L! ^ mCSS代码:8 w( @/ W- H& d- H: E
#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;
} 效果如下:
" s& `7 I1 F" C/ L+ ^7 w$ q9 A
7 @" `1 p. V( I% y2 c5 \
! e- U+ V" V9 B5 V, {9 j9 n* L$ P
8.CSS带有阴影的双边框
' H( h: K5 \( P S+ r$ I& @* X* qCSS代码:' e6 m3 L/ G9 N1 U# u
#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;
} 效果如下:
: }; R! |' K$ t' c$ R
1 {4 b" u, o1 \/ T# [3 f
' ~9 T1 Z$ l1 ]; s9.CSS多色边框
, ? X7 E I% f8 e! t# `, uCSS代码:- a# L6 v! E7 L! s" X( D
#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;
} 效果如下:, s; j$ n G# G4 l
|