CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。! x7 ~8 A/ k% M. q# u$ b* q' h
以下各特效用的HTML代码相同:
+ E/ E4 z, T5 O* S; m! S0 u<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 6 M( C4 E6 Y0 k. a% e8 \ E6 ?
1. CSS动画边框
# b, S6 |! W. q& t1 P; J1 f& |) GCSS代码:" O+ U. v7 u2 C+ `
@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;
} 效果如下:. T/ I- a4 o: B! v. {- v8 K% Y
2 {( v' B, S, _5 {
% X1 j% c8 T) T6 m4 T2 D1 {2. CSS图像边框! B M: K2 _( l% Y
CSS代码:( @# q6 Z, P9 e2 j" W6 ^6 s
#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; N% h0 D9 h/ U
0 N2 \7 r4 h& R2 i( h3 d5 I
2 ~6 a- z2 f# Y5 v7 }$ u" b9 [3.CSS蛇式边框
. X2 `) @8 U, m( s) D0 ^+ MCSS代码:% B: X9 ?9 c$ X% d i: 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;
} 效果如下:. F0 U( {) B0 d. n/ G: V
3 g4 i* {, X4 B' I% [
; s! R5 F; ~; `. g: p; G
4.CSS阶梯样式边框9 v, N8 V3 V8 z& `* V: Q$ H, y
CSS代码:
: p( d' _/ U/ I7 H9 R! I( {#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
} 效果如下:/ }2 q) {% d7 e! g; p- L
2 G, }% o$ D/ w3 m
- I% [1 d4 Z+ k1 Y0 J1 m5.CSS只有阴影边框. V! B8 `7 E6 y- a5 Y
CSS代码:! b$ m6 C. b4 a+ m8 ]
#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 _0 Z* s( o W
: Q/ f4 `3 l$ [8 g8 Z& u
; L7 a2 N8 B u& W1 m3 q( l6.CSS带阴影和轮廓的边框
, n I7 w8 q: d% OCSS代码:. F. @8 X3 L6 s, O6 D* O8 ^3 M! O
#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;
} 效果如下:
/ P+ o* b/ ~. W3 s- O- R _9 g8 [) h
0 R! U' E$ V9 s* T8 ]' s/ b8 L
& @: @* U$ x: J, X3 P" W2 l7.CSS少量阴影和轮廓的边框
) H; f; s: A( m, \) `; }/ W# @1 `4 ACSS代码:0 w1 o X. N6 _$ I* e
#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;
} 效果如下:& o% h# }) C8 c
' B! f; @3 y- t' c) P: J( b, d6 s6 k, Y3 W& U9 g; P/ L
8.CSS带有阴影的双边框
" a2 ~; ^* F) p _+ h/ iCSS代码:
5 _0 c6 H/ t; L3 ]3 A9 v#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;
} 效果如下:
! ]+ r1 k4 e |
4 E+ G( L8 ?* M. v' R, R
0 P7 ~- ]% u: t' z' K9.CSS多色边框
2 O/ [8 H; o* r7 U* b& Y6 @; oCSS代码:
# E$ D6 W- y' [* }- m#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;
} 效果如下:
* E1 ]* w$ N3 V0 c
|