CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
' s- P) F+ |* |7 n9 G& M) v 以下各特效用的HTML代码相同:6 F. n/ u' h0 ]8 o; h/ y
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> ' L& w$ Y' t' C: @& C+ O
1. CSS动画边框4 @# d9 { ]& T8 [. G/ q! c
CSS代码:5 a- N3 t; `. `) g) ~. K% g/ 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;
} 效果如下:
- f% ^) j$ t2 v. M, I2 ~# ^( O
% _- }7 K. d7 B2 {& f. k
5 W) p l5 m* X# V' [' ^2. CSS图像边框
" Q$ w( ]" F; r- R1 `" N; [' \CSS代码:6 ^, A% R" S- P
#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;
} 效果如下:+ G o# r4 G; O1 g: I( T
; R- m4 O" r4 n8 w! f* U' A# L
4 E; a- ]2 d6 d# x- O5 K4 c3.CSS蛇式边框7 v5 B7 R+ M0 K+ S7 O4 l
CSS代码:
9 m* v6 ?5 S6 B# _; H. q#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 G5 s( v- o8 V( Q8 g' T
. e5 X+ J0 ~. N* u
/ X, i. p" Q- X5 o3 |% `4.CSS阶梯样式边框6 E# K* Q: }& c% E
CSS代码:- k5 L: T4 e' ^! I+ P5 a+ r5 `
#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
} 效果如下:- Y; K% N& y- }& s! j; }
5 I5 O; Y% R! I e% a
" o8 H# [' O9 Q! S5.CSS只有阴影边框) S& t+ ~6 W) X2 e \: p
CSS代码:
# b' h) r7 r" n& v#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:9 o/ A2 S3 E) G) q% \
" P7 w% w! E0 c. y
9 P6 |- ~' @2 r" q' }/ G1 Q6.CSS带阴影和轮廓的边框
, ]. q+ K$ n9 NCSS代码:
3 g* N' m r ^9 G U* F8 P! _9 Z$ ^#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;
} 效果如下:
2 S4 o: k) L. w, r6 [; r
9 [1 m) E% ]: D! X
- t. {% g3 |; W7.CSS少量阴影和轮廓的边框+ P$ l3 |, D; J7 b5 _* ]
CSS代码:( o, Q# F( E7 F3 f0 j! w( v# 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;
} 效果如下:% @- Y1 Q) R2 K0 T$ v: V
( R0 t; m$ c% j& Q" e
! T0 ~8 E, ]- ~$ i, R; i& T8.CSS带有阴影的双边框
; t% [* q/ W, @, ECSS代码:
8 s& @, q$ x) v# m' D' {! 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;
} 效果如下: a; P5 f; _% X6 C( E
/ B, c8 J7 A* G! L2 z m
O4 v" t9 B/ e- T2 O2 g' g% @" V9.CSS多色边框
3 K2 B& G2 G, d/ CCSS代码:
! M$ `. v% S# ?. t& o#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;
} 效果如下:) I; ]$ e8 P7 r3 r0 Z* W
|