CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。( F& `" O/ h$ R; h
以下各特效用的HTML代码相同:
( F5 h1 I- |% C+ m" [7 f. i3 [<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
+ y2 L4 v7 @0 m8 F+ b3 A3 K1. CSS动画边框
" K$ g& w/ Z$ X) i; XCSS代码:
, F4 p" ~6 H, Y4 \@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;
} 效果如下:! P0 c/ d( N: d3 P& e5 B9 _+ P2 I1 n
' Y# Z* T2 \3 M9 |+ g
1 r( z; i& X! p
2. CSS图像边框
z% N1 z, Y2 T# A3 Z* CCSS代码:# N& y- \( ] d5 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;
} 效果如下:
$ F$ J& u. f9 p4 `$ c
2 G0 |9 ~7 `" J! |8 e1 ]5 W
0 @2 f# M6 J7 m$ G3.CSS蛇式边框
% W2 b) C( m4 d% x: W- _; T! E- ECSS代码:" D, u2 X f- x+ t' o0 C1 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;
} 效果如下:' Q1 C1 a) k, s6 C& c7 g0 g! K
* V1 k0 f, @7 L% t$ w( k
# f q5 f, r3 f4.CSS阶梯样式边框
+ b n+ R8 e, fCSS代码:5 Q$ b# S5 m' H3 c) |4 }
#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 |! j# f% o9 b6 s. I
1 L* | D8 y: U* [2 A0 H( Q
: O! [) W; v# Z# a5.CSS只有阴影边框
0 o) f0 y' c; l) I( bCSS代码:
` I5 A g& y* s7 ]6 S#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
' A8 l, T8 H! g; g3 C
' k4 @8 x# I) N/ u. @
5 E0 ~( T1 ], r5 d# W6.CSS带阴影和轮廓的边框% C0 ~4 m+ m4 R" V6 l! t- l
CSS代码:
# b U( d. H% f+ g#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;
} 效果如下:+ `. k& l% q3 C) Z7 U) P
7 R, f$ H, ]0 G" s; w
" Q6 b+ y" {2 _) p+ }& B5 d# P+ A( ~
7.CSS少量阴影和轮廓的边框5 \: `+ p$ M; G
CSS代码:/ W0 l' G' Y/ z! C& G
#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;
} 效果如下:
: C; f& p, N; N, C
% c. x, _6 G& p) N# B
% x1 W3 u% H1 k" F7 l& a9 Q8.CSS带有阴影的双边框 N3 Z! v' m: H; L1 Z
CSS代码:' h! h' S1 w- ^: I1 |) P! 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;
} 效果如下:# _* {7 L1 E+ t. n3 T
! q# H/ F5 K2 L3 Q# y5 @- p2 B$ x
9.CSS多色边框- U" H5 n% }0 ] Y& X* n( C
CSS代码:
. B5 w) b7 l6 Q* l% D9 G3 P, V#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;
} 效果如下:
# ?. ?2 _& ?2 b! W
|