CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
7 G/ t! s! ?% g* n9 o5 O# ? 以下各特效用的HTML代码相同:. X& e6 `) ~9 {
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
$ U/ n* D$ V' @1. CSS动画边框
1 O5 N, ~- S! e J, }% e+ P7 f, Q/ E, OCSS代码:" S. w F" V' G% m' {
@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;
} 效果如下:
( s. L0 R1 P: V. O6 T4 z0 `, g
, y4 d( t9 C4 O& k: G6 f& K; _ r7 }* x3 g
2. CSS图像边框$ n% D1 B6 D. |& E
CSS代码:5 c R: x- L7 f; v f
#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;
} 效果如下:
. }" T6 O4 W w& Y3 e1 l( q+ N
5 o0 J: |2 E# v0 a1 j- N5 z4 k" l3 a! Y
3.CSS蛇式边框
& \; h. T4 A$ S. \2 oCSS代码:
8 U$ u+ k v1 x#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;
} 效果如下:
6 m6 \/ ]- L4 t! Q* v
3 B1 [5 q0 U; h) H" s
# ?: E2 `7 S3 C( V" A& n% @ s4.CSS阶梯样式边框; U( s/ i' P& X0 {3 H D: [
CSS代码:& O/ j# P* O/ U' @, h8 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
} 效果如下:
; h, s+ g* x) f3 A( O1 G5 k3 {
) u# C7 z. R" Y0 J' n4 k |/ n7 v: Z+ c7 b t+ R* C }! X
5.CSS只有阴影边框8 V1 X% J9 n U- q9 V! Q
CSS代码: E* M* C1 b4 p- h+ c
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:0 M6 e8 A% n# T; c
?6 i. s3 L) K+ y. c8 `
7 g. `$ M/ _6 |5 r# P; j6 M6.CSS带阴影和轮廓的边框8 t' Z1 Q$ T' I
CSS代码:, q' P1 W+ I! J
#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;
} 效果如下:
: a5 f8 F/ p) l: r4 W" K* ]% e* x1 |
& d; \7 |" C% T" R4 f
: z' c$ P- A. B* `! I4 I0 s
7.CSS少量阴影和轮廓的边框
8 G) K& `8 x" a1 J |CSS代码:' e* `' h; C' e( n' X) N1 f
#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;
} 效果如下:7 W* W0 U( B" u3 u2 x% Z' y
9 ?/ A$ G5 _' z( c" G
. t3 T1 F3 C" ~% `( g3 E; u3 A# W. d) v
8.CSS带有阴影的双边框
% v/ | e4 s, [4 g) ZCSS代码:
|& { U9 u8 ]5 N1 F( N#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;
} 效果如下:& X/ X# U* F- g7 I* T
" y4 h, j4 _) i; @5 z1 u
( [3 n8 e" g- _7 V1 l9.CSS多色边框! Z* b) r1 i" y
CSS代码:
" P7 @1 r+ K, p. L% s/ 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;
} 效果如下:8 C3 N" u4 D! r( u( |) O, V
|