CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
q I* q) N- ^# F& w 以下各特效用的HTML代码相同: e/ U/ m4 \& @* q y
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> , o2 `' T! b5 j
1. CSS动画边框
) W9 A0 h1 ?1 l4 W& u( zCSS代码:" [1 F" q/ v& E0 {4 w, m+ [2 z) N* B
@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 J9 @- m7 u& m+ [" H# k
2 T5 b7 T4 M, ?3 x& {( [- r1 l0 i' ^0 f! D2 _
2. CSS图像边框7 y4 D2 T2 s4 V) p% {8 B& K/ L) \4 H
CSS代码:. l& @# D, a$ ~. C3 D3 T) b
#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;
} 效果如下:
% o. m" B* P9 L0 T
% x% o* `+ i3 h; k
0 F( k- B3 [7 {4 V3.CSS蛇式边框' |4 G2 i' D# u
CSS代码:- i6 q- q5 y& l7 L; A
#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;
} 效果如下:
, ?4 m" Q+ B" r8 N* v. J
3 i6 D$ w+ q }/ [0 |* m
- _% j% f: @5 S, q! T& m
4.CSS阶梯样式边框
7 j/ N" k) R- j7 {$ A3 |6 yCSS代码:
9 Z n" P L, A% m) 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
} 效果如下:
8 y* T% c3 v4 I* _$ z$ d
! ~' S$ S4 d2 }8 \) d' N+ [0 E$ b9 Q0 ^
5.CSS只有阴影边框$ {: ?& r0 A+ b: _
CSS代码:, [' |# N1 A# u3 `- @
#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 y. n, ^6 u6 A
, _, k2 r# A* L$ ^; ~/ z& X2 T
( e/ W7 a- Y4 [3 ~6.CSS带阴影和轮廓的边框) [& b- c0 K% `- c
CSS代码:" z2 h/ N r$ Y! \9 S
#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;
} 效果如下:6 |7 s/ l( Q* l8 a+ F4 K4 Z& G9 v3 I
: U& }4 H% T" k- ?
% w8 n! \6 p; e8 k$ M
7.CSS少量阴影和轮廓的边框& @7 o+ @ Z8 { c+ H$ l" }
CSS代码:
- H3 @1 _. I, f+ A" s" V+ ^#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;
} 效果如下:
, D- a8 U. q$ j5 P4 V
5 P" s2 l9 _! Q/ t/ L! ^
, k: c" ~+ ?3 b. p) b6 K$ \
8.CSS带有阴影的双边框7 _8 L+ k% [! i$ r9 t# c
CSS代码:
+ g- O+ `7 g) F# S- F5 G#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;
} 效果如下:: d9 K7 o* i! X! y( N
. B4 s( m; `4 ?5 P! f* @) q
1 e% N: D# y' \# E* T
9.CSS多色边框" E' G/ P# q1 J. u' N& t1 c
CSS代码:" t- P; `- ^' [+ }/ M- C" f
#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;
} 效果如下:) v6 E( y8 H7 a+ D6 g. I% n* W
|