CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
' Y5 z( x' m4 [3 o6 p 以下各特效用的HTML代码相同:6 k9 }/ g( y& {7 D
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> / V. q( a( C5 Z" H! s3 |* d: c9 X1 p
1. CSS动画边框
3 r6 z2 M6 B$ f$ _3 q1 T) E' G' h/ F: kCSS代码:
3 B" c( A! k' p/ a@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;
} 效果如下:$ F2 O$ T3 t1 e8 s
0 q8 ~2 V7 y1 X6 X2 z
8 @/ s& {9 k+ n8 ^0 t6 s2. CSS图像边框
+ {- a" O9 D# |# [CSS代码:& ^ G; N3 }0 T4 {; D
#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;
} 效果如下:+ z1 B: z, i; `( W) F! E
; d1 k) T1 A# Y$ B+ A0 ^( F; J
% H) @1 X0 T- Y6 G" A5 D8 s T: @3.CSS蛇式边框
$ \- |$ O' S0 B0 ?& j9 uCSS代码:% m( c3 s' e# p+ l( T* S
#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;
} 效果如下:
, [5 {) w; I) g' x; \4 c
& d# \4 _8 A2 \+ I
* w+ `7 w: e3 z; s+ d1 ?, A- z
4.CSS阶梯样式边框" r: A/ R, A' i# ~1 ]9 u
CSS代码:
) Z0 D) ^) A& @+ W, y! y#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
} 效果如下:7 S8 [2 ?" }8 S+ a8 c4 R7 z
5 g8 f+ L v1 V/ T, i5 e" ^, |$ A* p3 K, G
5.CSS只有阴影边框# @/ W7 L! k$ m
CSS代码:
8 g" t) R" t) ]% I; ~- D) g0 P6 l6 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;
} 效果如下:' }% |8 {& n) {9 d9 u' t# l- D
% e" `! P7 H1 K6 d3 n, G
0 w" J4 |4 v+ B( G! n+ R- H6.CSS带阴影和轮廓的边框
( {* n! c% z. q" `$ kCSS代码:
' q. {6 E( _) z: E! B9 Y+ ]- H#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;
} 效果如下:" `) }; c) S" R. ~# `6 K
4 z& b# B8 V# T* D& p0 `) h1 _3 s; j0 G
" f& e) X! x* b/ e7 w: ]7.CSS少量阴影和轮廓的边框
+ D: T% N. O7 H& O6 ~5 \7 GCSS代码:
0 l. i( x0 c6 e- s#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;
} 效果如下:
. Q n* I5 @& u6 v/ S
# N3 h6 C$ D/ J
" R, j0 m, q% s2 v8.CSS带有阴影的双边框6 ~, C, P+ a. H7 [6 m( m
CSS代码:5 ` x7 @: ^0 D5 o1 ^
#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;
} 效果如下:% ~7 y5 H+ y" w6 W& @3 T+ Y* a
6 w( R, R- b$ }( {' q
+ v6 _: x- u6 _; A; i! e, w. C+ k
9.CSS多色边框! i8 Q- \9 p) h4 p& A9 D4 C7 l3 K
CSS代码:- V% @/ G! |5 v2 `- G' B
#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;
} 效果如下:& v0 d4 l% `* R2 ?
|