CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
( v* |6 _+ B) V+ ?' T5 K: B 以下各特效用的HTML代码相同:
2 M) v/ z: s3 n* ?* Q0 n8 ~* A8 y% S<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
' c' i" K/ j' z2 `; o& @7 ?! f1. CSS动画边框) v' B0 @) F) _1 g. k! X. c$ a! C
CSS代码:) N$ }8 t$ h& ~
@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;
} 效果如下:
: c6 c# d5 G/ }: N2 k6 W- H
5 t u9 M% D' g8 t% ~8 l9 [0 K; r h& a/ W
2. CSS图像边框( f1 `$ H/ {* Q% _9 D8 ~
CSS代码:+ L6 x, u/ z( H3 O; P7 Q
#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;
} 效果如下:1 `& ^, H0 v! A4 [7 v) f1 R6 w; N
; D$ A9 e9 Y9 S" Y5 V" {
7 p" L& \2 O5 f7 S6 f3.CSS蛇式边框
1 X& ]# j* i' a2 P. WCSS代码:9 s" q- |( a/ x. G' c$ M
#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;
} 效果如下:
5 c, E, i! H. k; A5 S
6 Q: A1 ~- o C# K/ D" w2 {7 ?& Y
, N5 X/ s- |. Y- F: G6 ^7 H9 a5 v4.CSS阶梯样式边框0 g2 a! `* F+ C! j7 t
CSS代码:
* A7 C$ \+ K9 _! ?6 z9 V#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
} 效果如下:
3 V+ f# ^1 |" u* |' K+ `7 S
. P- N' r3 X1 f4 `" ]9 R" {# h) L; a: R+ B! k( {
5.CSS只有阴影边框5 o& F2 ^% k- Y A' B* Q0 y
CSS代码:
% R: d$ m; C1 @, z#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' A8 `# @ n8 i7 l
/ j+ N2 L% N" }: @2 \3 _; v$ g; b+ v# ?; Y Q1 u
6.CSS带阴影和轮廓的边框, D& E5 u3 J% P: J% a4 q8 `: e
CSS代码:9 _! i" p8 u0 I/ k8 |0 ?2 ^) P) R
#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;
} 效果如下:' }9 C4 q* j. y4 C$ U8 k
' b" U' C7 T1 B0 w1 k2 {9 G' j6 M
6 Y T9 d' F3 N( b7.CSS少量阴影和轮廓的边框
3 I& w: P. Y3 vCSS代码:
- `4 X& M1 Q6 o# d% w#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;
} 效果如下:: t: B2 ]1 w3 U. |) g9 n. _* T# `
7 h* L, }, d. R$ I1 z) Y: Q7 v% J
* [3 n* U& u7 N9 I8.CSS带有阴影的双边框; D' n8 @8 Z! X
CSS代码:7 S Q# h8 j, Y* U* T
#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;
} 效果如下:
) h r6 p' f& u! f; T
. `& E$ g. Q. a
0 R7 z8 w8 ?4 @# e9.CSS多色边框' }9 I: p( C6 K% k
CSS代码:3 Z* B/ T ]! [/ i
#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;
} 效果如下:- z; e9 t; B4 j( h E
|