CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。4 m5 [6 i5 @) R$ r% k
以下各特效用的HTML代码相同:) @2 g3 W* P* G4 ^& s' g; e( e2 H$ K
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
9 }9 U8 ?9 F: s8 G1. CSS动画边框
5 S7 q- J4 n) n- U2 Y1 c) D$ ?CSS代码:
4 z6 U& m- G1 R8 {4 U@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;
} 效果如下:- N+ ~: K, U. X V0 J0 |
# a8 w* _2 q/ p( ?# `1 R0 h0 l N0 [4 S4 w7 I! b" o, ]* s' d
2. CSS图像边框/ X1 n, b4 s2 |
CSS代码:
' x' M7 X, F. V1 C- n, `#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;
} 效果如下:
L9 b' \ O' g7 h3 ^; K. K
& p* \+ C* r0 }4 Z# F, I
& r" X4 H0 Q4 K0 q' X8 q( {5 a3.CSS蛇式边框- {/ `4 \7 \% m) t
CSS代码:
: e/ @* ~# K' g- M4 c#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;
} 效果如下:
* g, |1 v4 E) Y. h4 `$ W
! t" i& B: d5 G! f
" _2 R. k! i6 g& @6 y4 D! E4.CSS阶梯样式边框
/ [7 {' B. N' |8 D" C: dCSS代码:
5 F$ h( \$ q! o3 n. c1 U#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
} 效果如下:* [1 m2 G, y1 A
, H3 v. P f* z6 n& `( E2 ~
, w0 ^. }9 ~3 q2 G1 h% x5.CSS只有阴影边框
3 q- T9 A _% G: e8 `CSS代码:& \! ?- @, T$ j3 p( W1 @
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:- r' E, s4 X6 B4 W; Y- t2 s7 W1 `
& b( E; b4 w, t9 U4 [! E+ Y7 ^* c/ S9 P% ] ~7 r D' k5 q, e
6.CSS带阴影和轮廓的边框- g& _7 h; P* v! b! n1 {( e
CSS代码:% N f/ A8 R0 P! {7 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;
} 效果如下:
. K/ f* ^- j& @! l% W6 t
! ?% e- P G& [# w- N$ i
. b( n) p( g& p0 l) l) W7.CSS少量阴影和轮廓的边框 z7 Z+ ]1 b+ s3 R; y& t
CSS代码:; v2 { j% P0 d
#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;
} 效果如下:
) W# O4 f) O. t' G8 f
" t; m9 C9 r8 X7 m, ~1 y, g
7 W$ o/ b5 ~! \5 K0 O' a; i4 U0 |' l
8.CSS带有阴影的双边框' m3 ~# U! p! ~1 z0 R$ N- v
CSS代码:9 I2 O0 a& I" Q# g& c, s, p0 V8 R
#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;
} 效果如下:
$ b5 M8 K" e% F9 g: R# U
5 @- r: e- }! D8 O
" ~, B- @. C) d. j: ^2 Q# X9.CSS多色边框% `6 V! a0 n1 w8 v0 g
CSS代码:; a- ]3 L. \/ J8 @5 e
#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;
} 效果如下:+ j# X7 a) f C+ o! O! R
|