CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。8 z0 X' B6 n: }$ O( d( A! s. W
以下各特效用的HTML代码相同:# z% ?! K9 Y4 t. [* h
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 3 \( y8 C# {" H6 y7 R. |" |
1. CSS动画边框0 W+ ~# q$ C8 R5 b$ A
CSS代码:' X3 F% C" r' v6 X5 E9 C+ }
@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;
} 效果如下:
1 Y0 Z4 |* ~# R
1 F$ j" @7 }0 @+ h, {# H
4 ~/ b* m/ p& e( u- Z
2. CSS图像边框
) [: F2 @# B/ U% e$ |3 ^, |CSS代码:% @5 q7 V: G3 c
#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;
} 效果如下:
$ r, t, T5 }8 f7 `
u$ ?% h& O5 G2 b6 R
5 R" C4 Q* b: Z8 M. f% M7 Z- ~$ J( p3.CSS蛇式边框" ~% c$ k# ~% V' k" X [4 C
CSS代码:& y/ R% O! a# D
#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 h* L/ |2 U9 P
* T3 N( N( e" r! X9 T+ u. q/ Q( f' T2 T( \2 k& R: _( p! G. \! s
4.CSS阶梯样式边框
4 {& [* a/ F' i+ d) W) ]+ X8 kCSS代码:5 G2 Z! e5 s6 a8 v! ^) u
#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
} 效果如下:" P, J+ a- q. m$ L I/ R! G& ~3 M
1 w/ k* K2 H0 J7 q
5 ]8 L2 w' r* c/ q# g$ [5.CSS只有阴影边框
8 i$ K/ y1 \. }CSS代码:
9 ~1 w. Z, n. U' }) T#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
; p' F$ o! Y5 b
9 _& \- y* t9 v$ u- A2 ^, P/ P% \% W r, K6 S! G- j4 [
6.CSS带阴影和轮廓的边框
: ~6 m3 k; m2 s5 OCSS代码:: g* P- @ j$ s; B. Z" V0 k8 x3 L$ x
#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% {6 N8 U9 m4 e5 {% g
+ S3 S8 R( ]8 @' G6 _' |( W$ {% u2 m" |( s2 {% l+ t
7.CSS少量阴影和轮廓的边框1 J2 ?; J2 a5 j$ z% p% T0 Y9 @
CSS代码:$ d; \0 x3 n$ \4 ]- P+ 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;
} 效果如下:
% d4 n9 \4 i& h7 P# T3 w6 H
" d$ A. S" d$ s
" y" H! r& @7 K& ~0 |8.CSS带有阴影的双边框( l: W" X8 I0 X( \0 |1 g$ ~
CSS代码: ]9 p8 M' `7 a5 g! T8 O/ _
#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;
} 效果如下:
1 a" g! {! J4 I3 N$ f/ V
0 e( t' ?: Z! u( d, e: r
. J4 _; W0 r+ u: |4 Q9.CSS多色边框. D+ I/ Q) {8 U1 R+ j+ ^) ~
CSS代码:
; V4 I6 U+ 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;
} 效果如下:
: S; _ s, v; D" J5 H5 m5 t, _7 l
|