CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
. M! X+ J! C1 P% d- O' {$ s 以下各特效用的HTML代码相同:
9 ?4 O$ }) i" j<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
4 A f6 v* R: d1. CSS动画边框& {' R) N) i# C% g$ d( {
CSS代码:
1 D8 f y% _: @ o@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;
} 效果如下:) z4 @: A! _) n, |3 L
' G, h! R- @0 e5 R( n2 {
# T8 O" [( R7 h. i) Y# g0 t+ u2. CSS图像边框8 G8 Q) M) t" @) |( ~, d
CSS代码:, Z+ m- D* e9 q# t
#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;
} 效果如下:
$ u @' h* Y9 r
2 E8 V; e( T% c, L
" u5 N% B8 u& @4 Q9 h9 |
3.CSS蛇式边框" M5 H. d% m: k* T9 k
CSS代码:
; a& ?: L: S' R# u( 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;
} 效果如下: A. n$ l: J- f6 q$ B( ^6 K% x: ]% w
9 u7 x9 m* P# }8 ?/ j( ^5 {, B
* E/ N6 S% @; `, v1 @# s4.CSS阶梯样式边框
' d2 r# N$ [0 y4 CCSS代码: V5 h, S3 g( G+ }8 L8 V8 w
#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
} 效果如下:1 M" j$ |) s1 Y5 r
) W& q) X. y& |8 M# D4 c, |
+ B) V7 `3 M. |( Q2 C9 w+ L5.CSS只有阴影边框% O/ F" S! s1 ~4 M& y) i
CSS代码:
2 n% M' R5 _6 M7 ?1 x) d: 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;
} 效果如下:8 l4 n! m& D4 f3 C
) z. n) J# h/ Y. o
8 N, K9 o, r' m" f9 F8 m6.CSS带阴影和轮廓的边框3 A% {% ?/ K8 Z) h6 c
CSS代码:# I7 j3 i! U3 A8 k$ \9 _1 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;
} 效果如下:
! j( `& b2 \: `7 r# P( X
3 S! F H% ?) E2 e/ j
/ J3 g+ M! s6 w% u, S$ j) W; x
7.CSS少量阴影和轮廓的边框
8 e# Y6 W8 C# kCSS代码:4 u; l! |5 Z) @; v; s% I, A D
#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;
} 效果如下:, r1 r& k) ?: ~ r9 B2 ^
( q4 L) z( a5 Z
. n" u w1 L9 T; I# @
8.CSS带有阴影的双边框: Y) N0 L; T7 b7 Z2 o3 {# G2 @* W
CSS代码:
! j+ o+ c# U5 A' z9 z#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;
} 效果如下:
* L9 l! i( g3 e5 O! l o
3 i: a h6 _- u' ~7 O% u
" `, w# T1 E2 [$ |5 ?9.CSS多色边框
6 r$ v* h: ?. [3 b |' cCSS代码:
3 x$ e# d9 u- h! ]2 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;
} 效果如下:% O, R9 L5 G# ^' H! E5 H
|