CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
3 |+ }% L: t1 e; { z. P. L8 O- O 以下各特效用的HTML代码相同:
5 C+ {9 C ^1 w+ d2 y/ N0 p `) M; I <div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> N$ d6 P. w: {, M2 X
1. CSS动画边框 : u% ]4 |, e! e
CSS代码:
8 h% f+ N. |% C) d @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;
} 效果如下:6 H9 T) D# w5 I' Z3 v
" j# |7 }6 T9 N2 ^ 4 g0 f1 ]; z9 I& k, o5 p1 o4 D
2. CSS图像边框
6 q) k3 |, T6 N T CSS代码:
5 M3 E9 C+ G. y7 R- z$ N #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 m; e& g: o! j- i. ]7 T$ b
. {5 M4 N, G+ X: R7 t* }
2 J, u- W& w+ V" _2 |8 V
3.CSS蛇式边框 G6 b- V+ e% e! d- A1 L
CSS代码:
: _3 M& b6 m! z; f #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;
} 效果如下:
+ d# J# E. R4 E9 P0 O& A' B
+ H, X; }: y, t. W
0 [5 S: w# a: Z/ ~1 n 4.CSS阶梯样式边框
5 W+ a/ a* ?3 {- W8 V2 N CSS代码:" C; @/ {: O/ H
#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
} 效果如下:
b( R1 G$ o: J$ `; _! |
7 e" o% J9 e( p& M1 c# r; j
# ]6 {8 L* K' c 5.CSS只有阴影边框 ! t4 Y8 G- r5 h" }4 L P
CSS代码:" X# {0 \9 W3 S# W h
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:5 Q* X& C" o, z3 l1 x
3 ^" F& ^5 \$ v7 }- k+ H
" J# a M" V& i+ o y+ p 6.CSS带阴影和轮廓的边框
2 h# O7 g N7 P7 G4 E* d: q CSS代码:! H& y6 v) p7 I$ E0 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;
} 效果如下:% N) O: j: ~: P/ N$ V( l+ ~
7 ]* D* O) I* U/ Z7 n
* k$ L9 d H3 {! e; l: \8 U# Y 7.CSS少量阴影和轮廓的边框
/ @2 Q% a! u+ L7 b" } CSS代码:# ~* B# W/ s$ c
#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;
} 效果如下:' y2 R* a2 E3 ] H6 O! C
+ j' i# {- T1 B3 K4 u
% J( i" C. U' D2 L7 S: [
8.CSS带有阴影的双边框
3 u: P% w% J! V/ a/ s$ @ CSS代码:
" @+ t. Y2 H* b6 A #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 y! s' N9 N/ j
, p) C8 m) K5 e D / p/ t4 \- k6 r4 W
9.CSS多色边框 9 |; u; p- O1 Z
CSS代码:. k" B5 Q6 b6 t- b' I
#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;
} 效果如下:, V1 x6 ]1 L7 A( B' S