CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
4 x+ g, M4 |2 \/ m8 q1 ` 以下各特效用的HTML代码相同:
$ ?: P/ J8 P- t. [<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
1 F& ~$ k- P) b5 r# P# |3 N1. CSS动画边框; _( k% a) d; F) ^; b8 m
CSS代码:8 G3 ]3 }$ [6 K: S9 f( ]
@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;
} 效果如下:) w* o+ P+ P/ i$ P" ^
7 }! P' [% e, d
6 n5 p, x7 l+ _8 f, Z2. CSS图像边框
0 \9 D5 |9 c* i2 ]! v$ h) tCSS代码:0 e# g8 g% S5 U3 Z% @8 u
#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;
} 效果如下:8 ?/ _# R0 \' }
6 z( R) U" e* e' l
3 j0 U- [ |' Y* @* @) I# Z
3.CSS蛇式边框
. ~( O/ {5 g s+ q+ R* A) fCSS代码:
' u. F$ `& W, O#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;
} 效果如下:
. V: x! Y$ i2 z- }4 Y5 o# r
( K; h+ b- b* @) v
( l7 B+ c6 x- F: D4.CSS阶梯样式边框
2 W. e' @. }) Y9 H$ F& e4 j% _+ PCSS代码:
* S% i2 v" N2 F5 s#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
} 效果如下:/ X9 p+ k) ^* ~ A7 N
% H1 l8 o4 H: q8 b+ @- ~8 t
* t4 j- [" Z, b& r! P b8 I5.CSS只有阴影边框; F2 d- P5 o& `' q6 \/ ^
CSS代码:
7 v+ q& Y8 {, L#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:: S% Q1 B2 ?9 a3 c, s
5 @1 M; d4 o, @2 x) X) ]
5 M6 V2 d! g$ X, S" N0 ?6.CSS带阴影和轮廓的边框) i1 {, d* d5 J6 r: q( m6 q. H9 H
CSS代码:
8 [& M2 W9 f- `8 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;
} 效果如下:
! v# r- B; Z6 `2 j1 |1 h- N
# h6 t0 g0 V7 c; L9 H4 J$ Z, Z! v: }4 ^4 y
7.CSS少量阴影和轮廓的边框+ I8 Y: Y6 f) v
CSS代码:4 W h5 ?4 h: Z8 i2 V2 D, b( U
#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;
} 效果如下:
; L8 O2 e% G+ m- `1 F
8 v8 e4 a! x2 T: I; z
; s2 H8 n4 Q; |/ Z7 X
8.CSS带有阴影的双边框
) {% g( ?5 O |6 O0 ?* S* b2 SCSS代码:
8 y9 K+ X' i4 i4 N6 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;
} 效果如下:- {# @" u9 O2 @" D6 X
. X" c0 v) B) A5 |/ n
) N. U4 n0 A1 A
9.CSS多色边框- H. M# n9 p4 g8 D- F
CSS代码:
" o2 O* |! w' }7 D$ d* d#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;
} 效果如下:
8 z3 J$ G* r; D0 h8 ?* l' X$ g
|