CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。: M- t$ C; a0 N# m2 m
以下各特效用的HTML代码相同:
" Y* ~/ R L5 r1 U
- <div id="box">
- 编程适合那些有不同想法的人... <br/>
- 对于那些想要创造大事物并愿意改变世界的人们。
- </div>
" o6 A: N$ i- d: t+ i& `1. CSS动画边框7 B" w( Z* t' S" B+ T# f" g1 c( ?! u
CSS代码:
6 C7 l1 @$ j* X( Y5 a- @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;
- }
效果如下:
( k: q: i$ l$ v) e9 w! a
5 W8 O) B* M$ F6 s) v
$ u* {6 V$ d6 M" g* F2. CSS图像边框) k% g# d* {4 L2 M# t/ g
CSS代码:
+ V% F4 n- s1 }* @4 t( E; g* o- #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;
- }
效果如下:: p- w8 @, n# g% \& B; }. f
& w7 z; k" y8 u% M1 B5 r3 z+ l4 U/ u
3.CSS蛇式边框
% C* q$ m. N) ?. D2 _: tCSS代码:- ` v& U2 K+ c% \4 a2 I3 N: u" k
- #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;
- }
效果如下:% G7 x6 v0 D* u
! V& f2 h* W; ~( ]( z, [
7 }7 o/ f4 s7 }5 [( y. ~4.CSS阶梯样式边框
" B9 o. M, _& J0 j7 u, K" l" LCSS代码:/ {& A) a6 z2 l+ k' I |! g
- #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
- }
效果如下:
( A, D3 b9 @- J. s0 e( v0 p1 o
2 r* ^. o# |' z
* @3 I% F5 j# }7 m, O2 c5.CSS只有阴影边框. x8 B% m( ?+ U* u0 o! c
CSS代码:
! o$ G. M2 S& ]3 ?& g* ~3 p- #box {
- font-family: Arial;
- font-size: 18px;
- line-height: 30px;
- font-weight: bold;
- color: white;
- padding: 40px;
- border-radius: 10px;
- box-shadow: 00010px white;
- }
效果如下:
% f# k" _2 ?, i* v( m! s# ]2 l1 v: l
$ s$ t6 C7 j9 R$ o
i6 c8 e' d* A7 ^" R/ l3 V6.CSS带阴影和轮廓的边框
2 m4 f! T3 q1 p- \% k: M+ FCSS代码:. W* V) b& G1 K4 k: p% m
- #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;
- }
效果如下:
5 u2 L* @$ K1 F, t6 W( {
7 Q6 {. l7 q! y6 ^6 u* Z" B) I( F7 L: y. w5 m2 N; Q
7.CSS少量阴影和轮廓的边框$ o' u8 B& n1 a4 p, ~1 w0 G* N
CSS代码:
) H. A, N* T3 s) T% Q2 c5 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;
- }
效果如下:- k% U5 G; T$ ~6 c! g, M1 G3 j
8 s G2 Z2 Q& k& ]# ^
; @: }* l6 d5 M- z* {8.CSS带有阴影的双边框
: e9 D0 a6 S. L, O# pCSS代码:; L; O2 G7 s* h& N2 f% c
- #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 r$ p; I( O, H' g
0 \5 @" c1 t$ ]8 @" u
3 n& f: y$ Q5 v5 {6 ]0 D9.CSS多色边框
7 c" B7 b) Y% x% kCSS代码:) @' h L4 o' l- Q. 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;
- }
效果如下:1 M, Q9 X1 i d3 {2 _" z, p9 W) U" I1 j
|