CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。* d4 n) J4 x( q! ^/ _0 g
以下各特效用的HTML代码相同:
. j. g9 D# k7 \0 M: X3 }3 \7 p) }, {<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
( l8 M- j) l% J1. CSS动画边框* J9 V& L1 p6 u0 m! s; s$ P/ A% d. j
CSS代码:4 q/ r: I" u8 Q+ ~4 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;
} 效果如下:7 y4 f( n; f/ q( i4 [
* x5 H+ Q" _& R3 f! m7 A6 W' x' K" d
, l8 T- I/ |! z+ W4 H9 Q
2. CSS图像边框. Y/ T; S) | j' c5 }2 ]
CSS代码:0 ^9 L( K# n5 o3 {& r
#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;
} 效果如下:
7 j; S. j2 h; ~5 A1 _5 P6 W
; w# l( a/ [* I5 h
: y1 j6 p: E' ?; B1 |3 G
3.CSS蛇式边框2 H) d8 F$ v3 K0 X
CSS代码:
1 U* m0 ^8 f. |. 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;
} 效果如下:$ O3 V7 A3 I- ^( |
! f2 \: ^0 i) E! h
+ t4 F" p% }# Z! r3 m# m4.CSS阶梯样式边框; j* p5 L! y( S. S3 f) L! f0 W' w5 r
CSS代码:2 K# q! N8 T2 j
#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
} 效果如下:
4 x: U- g, E, ?" F- y
C* P* s$ F# e; s, |
; w Z" e) i5 @* J# n4 w; l5.CSS只有阴影边框7 ~) A% t( z5 i/ V7 j/ U
CSS代码:+ L/ S) |: M* \
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
( \. Q$ @; q0 U# H" r& r* v2 @
% [4 C& d7 K& y+ i v7 d; ?: _7 x; K
{$ G; T( p5 l6 i) y: I, P) L
6.CSS带阴影和轮廓的边框3 k& v; M. {* u
CSS代码:' U! n0 z, z* ?: v0 f4 t
#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;
} 效果如下:
! X5 c0 G1 u Q& }
, p* O! x6 L3 P3 F' ?
9 i" k8 X9 y) s( B2 |7.CSS少量阴影和轮廓的边框
4 U- L9 O* t" D1 T4 ICSS代码:
' M: r! U$ `2 ~2 V#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;
} 效果如下:% B8 H" A! b' |9 _! _, `3 |
: u" w+ X3 ^. }* v$ J
' @, P, m, N* g4 q8 @8.CSS带有阴影的双边框
' N8 h; f m: J+ oCSS代码:9 O3 R/ K! S% L+ h2 B2 i
#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;
} 效果如下:
% b- k+ L8 G# U# e
2 s/ }0 A6 x& z- |4 t$ m1 l# }: R2 O1 Z- C5 P8 `
9.CSS多色边框/ a! u& G! u4 r# E! V
CSS代码:
A1 Q' i/ r" Y# g#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;
} 效果如下:
* P7 {* ]7 ?' v$ W6 b1 m O
|