CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。$ J' T) u$ J+ \8 i7 K
以下各特效用的HTML代码相同:! C. p1 O; x$ o ]: l) T# f6 q. ?
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
) X0 D8 M4 s+ ~" N: } q1. CSS动画边框
6 b" k- O* q& O% E% m4 U8 JCSS代码:
( O: k$ f" l0 [' r U@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 h+ @, y9 [1 i A* n
" u" _) [5 Q* R9 q
8 D& J& @0 d8 c- W2. CSS图像边框
( M- T$ \5 s J7 }CSS代码:
9 a6 ^/ T9 j: e4 ~# {#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;
} 效果如下:/ a1 S: D0 x5 b6 y( R# i$ V# x# N
# B% h$ s8 \( U4 [4 u+ j) o# T3 A7 O- {7 x t2 n" _
3.CSS蛇式边框# {; A( W' h, J& ]* H
CSS代码:% Q# }7 L4 I6 Q5 _( M* P: G% t
#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;
} 效果如下:
9 q% X9 u0 m6 h z
+ p M0 O4 {# J4 r4 B7 S8 w3 C x
4.CSS阶梯样式边框
5 ~* d2 B* ^8 w5 I# q* Z. {CSS代码:
9 I K8 `3 o+ Z! }# A. z#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
} 效果如下:: M4 z0 _1 U5 d; t) {+ q
" ]" ?) }4 w6 w: F# r* x$ p+ X; f
# }2 a9 x( m0 o8 \5.CSS只有阴影边框
+ |' Y' `: N7 c) G7 @; A5 j# HCSS代码:% p/ J0 d) J# @& B' 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;
} 效果如下:
: Y7 l; F2 p: I9 `/ [4 Q% g
' `7 h8 Y: q* c9 g4 }# O, B
6 c2 K# G \) z3 f, ]- v& [, ^- w4 k! v6.CSS带阴影和轮廓的边框8 _# K# x/ M9 v1 F+ C9 B
CSS代码:1 s0 K: N. |9 H( 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;
} 效果如下:
) {( l) K% b/ Z h
* [: q( l. ^6 o3 V1 W) J [0 D- F5 Z: [+ V. L
7.CSS少量阴影和轮廓的边框
# ^; ^4 p3 w9 u. B& A: N! O0 X; z9 \) kCSS代码:
, o0 X* U3 r& p; E7 b& C5 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;
} 效果如下:- |" ~' y9 B" K- r) O
2 h8 j! `& d @7 s! A: D5 n( P
) g$ t+ X: k2 t1 G1 _& Y4 \8.CSS带有阴影的双边框
3 d- t5 w3 Y' p( u i0 ICSS代码:$ ]9 {5 R# b0 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;
} 效果如下:! a4 |7 G+ d" \4 W
4 a% d% J: O7 v: ~# E# I
4 H. F5 k8 g8 h' M9.CSS多色边框
! C3 S7 {4 J9 f) V4 K, t6 B! Q* fCSS代码:
! p2 q) E/ }& z6 J#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;
} 效果如下:
& F: I% A8 X* S$ M) Z
|