CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
3 v/ b+ ? X0 _; F. j& Q 以下各特效用的HTML代码相同:5 g# }6 o, ^% N& e
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
; t$ T! Y& N. P) F1. CSS动画边框
/ Y' z& g+ L3 ?# ?. {4 ]: r* t' i, v3 S) QCSS代码:
+ E3 e# i- u+ Y( N& l@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;
} 效果如下:* e% `( a8 ?( _8 ]1 q) \. }0 D" f
- r7 ?# f+ ^# o
5 o1 A4 Z' \0 x3 L2. CSS图像边框
! i d+ \" W6 K; G" L: oCSS代码:
2 d7 ?) \0 H0 [6 o#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;
} 效果如下:. h0 p8 p. u- ]
# O. D* s$ t% ?' U. p! w; n$ v# t( Y8 B9 D' m" o: V
3.CSS蛇式边框, ]: R: \" I0 \6 Z1 g
CSS代码:
$ U8 B6 ~ H) T& U) F" s5 {0 l @#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;
} 效果如下:
/ P+ J( e" R1 C$ Q% a
& Y3 z- b6 k8 f$ m. f* c$ f
# h& u* z# e2 }* V9 t$ {" K- x
4.CSS阶梯样式边框
% T, o3 T' |; W1 rCSS代码:
- C6 [4 q# d6 a#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
} 效果如下:; U/ C7 P4 z: x8 _
7 F2 i) b9 S! ~0 W6 |
- A9 h5 p" e9 Q& R8 }4 D( d* T5.CSS只有阴影边框
+ o& e3 h" `( W8 L+ z" A3 O1 N+ z7 YCSS代码:
: K. u! h A# R$ R#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:/ x/ y/ J: u$ [" Z( r3 Z5 ?! g
" T! A- z$ @5 o, d# J6 q8 Q
. |0 |/ v( ]% \) i- `+ C6.CSS带阴影和轮廓的边框
4 g! b9 K( n3 S% qCSS代码:
4 g% J/ j2 E0 M* G2 Y#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;
} 效果如下:- M/ \1 \6 K) m+ O( C1 U# s9 B
9 p" n2 G5 Z* \& o
( e3 c) R5 ?# q7.CSS少量阴影和轮廓的边框9 z o3 q) F* G
CSS代码:
7 H- ?) M2 v. S3 X6 ]- 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;
} 效果如下:
) n u, h' K0 b2 Q2 A
% P4 m( g5 s/ A: o/ |7 |3 A0 @$ f9 }0 q. N- q
8.CSS带有阴影的双边框
9 D! M; Q+ M* f! P' Z5 @! F0 K! w7 aCSS代码:; {8 G, w) O( y$ A. k
#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;
} 效果如下:( ^. _0 O5 j$ }2 t( C
: V0 e* E* {& q5 X9 E9 A3 f! m) A9 w, Q* Z% ]& d% w" G& @2 j
9.CSS多色边框
4 l& `2 K+ g9 mCSS代码:
o$ c3 @6 j& @ G. R& j#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;
} 效果如下:& [0 Y, X" }2 j
|