CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
* _6 X+ r! Q8 Q# C 以下各特效用的HTML代码相同:
7 P+ S2 q! s2 J! k4 z<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
9 G8 v; T8 K7 L( T" T+ H1. CSS动画边框
4 \7 _9 Q5 d2 a- PCSS代码:
% c3 W. ]; f8 j4 M@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;
} 效果如下:9 B' m" {0 f5 k! C" {* b3 ~4 e
+ M a/ `. h7 A1 H
& R3 j6 Y9 K4 m* n' J7 p0 e) n2. CSS图像边框
5 H+ A( K a' r% L2 n5 R Q1 GCSS代码:7 c2 L2 ~ h s C
#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;
} 效果如下:/ K( W& B! Q6 P( [
3 k0 a( Y. N. P0 N2 {0 m2 H+ O' \7 X- [6 ^7 i
3.CSS蛇式边框
' C8 a4 y `: @. w" t+ A; O& A( lCSS代码:& b- b% N! h8 ^+ @2 N 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;
} 效果如下:8 R* j5 r9 _2 U0 f# ]6 u
5 o) A- E2 V8 e
' g8 K% f& p4 ?2 L2 \
4.CSS阶梯样式边框# x) `; y5 q. G+ |. p- Y
CSS代码:
4 U3 K- H; p7 U1 \8 b4 h' D#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
} 效果如下:
. M6 J$ ^$ n8 _) d M7 o
' U/ _2 d! K3 K/ p4 Y7 J
, M: {* u7 g) b. j, U2 \5.CSS只有阴影边框
B+ y7 c k3 u% t8 I( A3 y* wCSS代码:
, ~; ^: S/ G1 q9 G$ y#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
" K* x# }. `' [. I, V0 y
' g9 ^8 {7 h# x! [
. z, m& g; T1 p; x4 i: f, a. o6.CSS带阴影和轮廓的边框8 F% N: C x9 e P& n8 N" j2 j5 T
CSS代码:
/ q6 N) s, H, o8 u#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;
} 效果如下: e7 g! t5 I8 a, v3 ? [2 X
9 \" {" H9 L- }3 @! q+ {# U5 i& o
/ q& t T% j& m7.CSS少量阴影和轮廓的边框: E9 ^0 Z* J. Z
CSS代码:
4 y9 _0 X) i" I' R5 ~! \; E7 Y#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;
} 效果如下:
1 P5 C7 D# o! v" [0 h. {
8 k2 q+ r& r; v, B, ~, O- l& I
8 J3 j' X6 I" h: R @3 y
8.CSS带有阴影的双边框
" z3 i2 x' C c% [# b: ^, Y4 VCSS代码:/ A2 D% c- i. r; g1 p+ P( J' Q
#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;
} 效果如下:
2 t" I+ d3 y# w6 [ w( Q7 G
2 ~' O+ Z5 r: n; y" c% o7 O$ _" D, S) C& O$ u8 l, T( R
9.CSS多色边框
8 J$ Z. u! k0 ], i5 l* {: g$ [, FCSS代码:
3 p& y' Q3 d. J' X#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;
} 效果如下:& V c1 K; @ h+ I+ x" r! a
|