CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。" P" ~. f$ j8 j; t5 b) R. D
以下各特效用的HTML代码相同:
- [ Y1 H$ K9 ^0 \<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 1 j* _" M/ L& d& ^$ q9 s
1. CSS动画边框% ]& y7 p$ J2 ~
CSS代码:6 `9 F* P. a3 a! L! I5 Y1 `
@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;
} 效果如下:- ^5 I- o. R0 l( e6 R3 _2 q
2 f: a; m- z( E! y- j$ J7 F$ E0 ~: N. B
2. CSS图像边框
# j! n% h1 y; d0 F: _CSS代码:
9 Z! l/ ]& v* m* `1 {, R#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;
} 效果如下:3 m1 E! P6 x+ s$ r1 s( M8 @4 ]; c% v( E
4 L: B- O1 K$ p* q% d
* o2 E7 V! m3 Z3.CSS蛇式边框
1 \9 |! i7 K6 @6 q! P F+ z$ K. lCSS代码:3 N7 L$ _. y( j6 S1 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;
} 效果如下:; O; G- C7 H! g9 }" s; d* E% D
# }/ b4 ]1 ?% D8 G0 H C
, N% d6 W. z1 v4 X
4.CSS阶梯样式边框8 P4 d% X. O, Q% W& _$ \, J
CSS代码:
: j6 m! y* g0 s# y#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
} 效果如下:
( i/ H+ `: t. T: A8 d
% ]9 Y* m3 G9 \2 \; T, |/ e
; C4 Z) ?8 g! M- M5 l+ {5.CSS只有阴影边框
4 `$ {2 c* g5 v GCSS代码:+ s# X, M5 r( S, w+ r
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:2 d B3 F! {5 X/ h% b# B
7 B* M/ n, s, e$ t- ^* U! _$ v& L0 K3 ^1 @+ Y4 y/ d* r' c# ]
6.CSS带阴影和轮廓的边框
) Z4 e$ N) g" W( Y9 aCSS代码:/ @. m. H7 I! c) m* l
#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;
} 效果如下:8 L" @. R. |( |" o% `
: f3 w5 ~+ Y/ X4 r9 {( w% L
% K ?; N! E4 z. v, m. [/ N3 n6 }7.CSS少量阴影和轮廓的边框; i, e( M0 U$ r0 s
CSS代码:
7 j: J+ D# o, |+ _" }#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;
} 效果如下:
- A! s4 y$ r3 {6 p O0 u
* Y( X) E/ \3 I/ J1 r2 N7 D7 K1 G
, Q" t3 P5 w5 b& y5 K8.CSS带有阴影的双边框
* \% u# k1 ?6 D$ }CSS代码:
- Y2 H" ^+ y( P7 f! [#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;
} 效果如下:0 i( V5 S2 X4 w0 }7 K+ H" q8 Z
& k4 v9 R% l/ Q
0 L$ f# {: o& R- w6 U! |/ O/ X9.CSS多色边框
- K3 a0 N* m" TCSS代码:: K- @5 F: x" X0 P+ O2 Q
#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;
} 效果如下:
1 h$ h& ?7 j( X- Q' n G
|