CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
. g; E: z4 ^4 F 以下各特效用的HTML代码相同:2 ^4 l6 v0 l# ^
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> " N( T) a. }* ]' Q- b
1. CSS动画边框
' E0 }( a* o' K+ P7 TCSS代码:
# T' b9 u, L3 m! Y@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;
} 效果如下:0 A7 p. r; G6 Z0 V+ j
1 Z, N k2 j3 N! K& M p8 `! V+ T4 T9 ^0 k: d6 @
2. CSS图像边框6 t$ N4 ^7 X8 s. |7 B
CSS代码:
. g$ P; h7 M& Y#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;
} 效果如下:
: T, T0 i& J! V/ ` l0 F# ^1 {) y
: J) A; {; u/ J# k( p
, Z: ?( l6 L7 r! V- E$ [
3.CSS蛇式边框0 H# L& t9 Y" l$ z$ H( B
CSS代码:) U$ r( D+ H5 Q9 U7 V: f: O
#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;
} 效果如下:( m7 M$ M5 x! v7 F L! x7 p; x
3 z" g7 B) L% D ?& h: O
) s. i1 _; ?. b9 O9 \, d' t8 W4 J4.CSS阶梯样式边框
. b" m' h' D8 `# F8 nCSS代码:
8 Q/ ?1 G4 t! U1 H- ]; L#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
} 效果如下:
; h) `2 |0 h. B {: D
, L8 b6 g9 X" S
' W' f/ z1 l1 h% |& m) k f7 R
5.CSS只有阴影边框) c: B" @% P T
CSS代码:
' d0 w" A4 z2 K3 D$ \& c#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 y" H5 W* e/ F% Z# Y2 |
, a3 e) p1 t' M3 D; y
: R9 r# u; z& ?% `# b0 C6.CSS带阴影和轮廓的边框+ j h. A% L" U
CSS代码:
7 p5 A4 x0 e) a#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;
} 效果如下:
+ g2 y! P3 k6 ` r: }* \7 i
1 O9 {' ^7 k0 Z9 o3 D; W
- l2 B5 |0 b. N5 \4 T
7.CSS少量阴影和轮廓的边框7 I3 l4 Z6 ~9 k$ b& S/ q% {
CSS代码:7 p: }" T0 {9 M8 e; S6 d7 c
#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;
} 效果如下:
, g" {( ?. S5 J: b+ h: t [* `
0 V. z$ @( b- @5 X: W
1 d3 { t, L. E1 x5 O8 O* N8.CSS带有阴影的双边框
" `) U1 E9 P- p0 nCSS代码:. L4 o' n* ~9 [% p
#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;
} 效果如下:
, S j, { p1 V6 E
# j! f, U2 w+ @4 H/ v7 k
# d- ]% j! U4 L, Q: H; i
9.CSS多色边框" z4 G5 m% v8 X0 J
CSS代码:
1 C' R$ v, D7 C ?" w#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;
} 效果如下:
& P7 E8 X. V5 m' p2 I
|