CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
! a# A: ^- _/ z4 z5 S! X8 ~6 x 以下各特效用的HTML代码相同:
7 @- j! w* E; T8 a; ]<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
& Z1 \2 y" U ^2 ]- T1. CSS动画边框 @! S1 j/ I9 U- |
CSS代码:
V) U# F2 P3 L/ Z7 S@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;
} 效果如下:. I8 N% x& H$ O& f1 _
5 x' a" ~1 V4 s; d( ]4 S1 u
. p! ?/ [0 T* `/ L0 ^
2. CSS图像边框' z$ k, D+ N. h# B) H% `
CSS代码:
* C1 g8 L0 `0 A#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;
} 效果如下:
% j/ _: h: R# ^4 L5 N
9 E) M( y* Z+ M9 W( [* e& k* e# d5 e2 v6 b2 e. V* c
3.CSS蛇式边框; c/ D/ W- U+ y. j8 \
CSS代码:( C( L- `( T1 E& K% I
#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 \ d% e3 p! @: Q( k0 c
" ^$ {5 x6 Z0 c: k. h: \
$ s' |8 C0 w: X4.CSS阶梯样式边框9 n" x8 ]. Z& @( h- U& ^
CSS代码:
8 I+ R& D* [+ J#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
} 效果如下:
# ]2 D& K4 \, R: f- U
) U( i3 K8 D2 K
% D, r# b) P! S. A
5.CSS只有阴影边框
: ]7 `) K! C- `3 c/ LCSS代码:
0 k. b6 r9 S6 e- X#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
+ J5 q" |- w& O
$ J" S+ o7 c, i1 o/ a; L2 t+ D6 ]) k: E3 J ~7 k; J
6.CSS带阴影和轮廓的边框
. L, a' }) _7 g; n: b4 dCSS代码:
5 d0 f5 b$ G" R9 e( B% ^# ?. 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;
} 效果如下:: Z' t a; B. X) w& Z& K( ^
0 f$ q8 L+ c6 N# G2 g6 s5 B" G' H+ w. |: _9 W# ]$ _
7.CSS少量阴影和轮廓的边框
7 U7 h$ R# K% x3 ~5 i$ nCSS代码:
0 \0 D+ \& X. b3 ^# t. `6 c- x#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;
} 效果如下:' Z1 k5 y# _0 `, h6 m
" N' l' B. j2 r, [, V# y
- I, T! x7 p8 D) `
8.CSS带有阴影的双边框* n# l/ h9 |' [; J3 l$ C
CSS代码:
' q- X- g% ?+ @) [4 K#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 I2 B, a1 v c, a/ X
! e" f, ~; S! y. x$ ~! Z; T* l [ m ?" k
- C& t2 }- V3 \ Z& B9.CSS多色边框: q9 W& `7 o; W- w
CSS代码:
6 D& c+ L8 k4 S" z% f# d. D) r* N#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$ R: p$ k. k q- `
|