CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
9 U2 A1 ^6 E# @; |( v 以下各特效用的HTML代码相同:, @( I l# V) k# a$ k& R( z1 K
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
J, \4 P# H& N! a$ L& G* H1. CSS动画边框
2 r+ c& e M4 ?CSS代码:
3 v6 q3 q J# h/ G@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;
} 效果如下:$ F* X2 ?2 T _5 R: D; ]5 r- h
: m" J1 y! n, R2 ~/ x; O' ~/ P3 J) q$ v
2. CSS图像边框
1 M/ K! b7 _" E0 a: N3 u7 G- QCSS代码:4 X2 d/ h8 H# O# I' n
#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;
} 效果如下:4 o" `$ \" n2 R4 ~# p# i* [
4 k- r. P/ W3 B, s1 D W
8 O" w1 A: J0 y- Q" R3 N
3.CSS蛇式边框
4 ]! ^ n, w5 _- C% v. t6 GCSS代码:
/ N6 P: J* d! J# j#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;
} 效果如下:
. g7 b) H( u( w! L
" z! s# _% B; [& u
* T: I, H! K9 D; n; t8 t- p% P4.CSS阶梯样式边框
$ f# o: V- q, S5 {CSS代码:/ V* w1 l6 n s' [2 M
#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
} 效果如下:$ m" E' G# Q+ d9 H9 d1 d/ G
' B! B& E( a. Z# |/ z& H; t
7 N0 o' M3 W2 {& _# D/ j5.CSS只有阴影边框7 Y( v- W" b& y: ~1 ~6 o p
CSS代码:6 t8 V) E- w3 |, t. m" i
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
6 l* B$ Y# L( o, l
, U8 C1 c+ B# z N' \7 l' W
$ T) }9 u l Q0 C* N8 W6.CSS带阴影和轮廓的边框
; F3 X5 U k% i+ ]6 U( n9 |/ K5 ?CSS代码:$ r2 O. z8 G! 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;
} 效果如下:0 J8 C- Q( t0 V
: J3 s! \& v$ {
" @) S3 H$ I1 B6 n* F7.CSS少量阴影和轮廓的边框
+ E7 s8 D4 s m) uCSS代码:+ r0 i9 e+ a. I" k) s% F5 A
#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;
} 效果如下:
) }/ o; b8 f; J! {' w
5 l5 i& r) O; @* P, L8 O" v5 T* A
4 {0 q1 i) f( n$ t
8.CSS带有阴影的双边框
1 T1 T- o6 \8 {+ u1 Z2 i+ R( jCSS代码:
8 q! G3 c: l6 d& j: ~ }#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;
} 效果如下:! t; f b+ S, z' M1 Y: X
! S V9 A4 ^% D( l) [* L& t' B7 m3 L, E' u p0 J3 i
9.CSS多色边框8 Y: g1 q1 b3 P& X e& @: S9 k" T8 }
CSS代码:
6 _& `7 t2 C- W8 U- \#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;
} 效果如下:7 P6 }8 N) T7 j- d) N4 V
|