CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
6 { ]5 N( O1 }# [6 l$ S 以下各特效用的HTML代码相同:
7 n4 R$ k+ Y- ~# ?+ Y# }<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> , u# w; w9 g% ^. R
1. CSS动画边框% H$ T+ Q, E: s: G ~4 O
CSS代码:
7 B7 `) k9 S8 a. {& W! f* q@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;
} 效果如下:- Z# t ~7 G! D$ d8 I) c
6 i) k# P4 H) ~9 M! v4 {# L
+ r7 Q) A9 w( O2. CSS图像边框& F- I( O+ G1 G4 L: x L
CSS代码:
& ?2 A, F) B. O5 I% |#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;
} 效果如下:
8 c& `/ ~/ T5 T3 j) Y* Z4 h/ X
- H- F2 u3 ]. e# H) l& N$ e
/ }& |# I) T" U$ e3.CSS蛇式边框7 f6 B4 k' u; R4 K% S5 Y) T3 ^
CSS代码:/ `/ R% M6 p2 H4 _
#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;
} 效果如下:& u: S4 q) B& Q) _: K, i
+ Y3 A, K2 c" `, N
' I; I9 m% y+ w2 b
4.CSS阶梯样式边框" }" y, W& `9 E8 r( V# A
CSS代码:' l* S5 p# j: H4 x
#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% O5 F" W# i
* k5 I3 C Q. v' A3 D8 c) G# ]& @- `# c$ f% W( A+ V8 F
5.CSS只有阴影边框
# q& \" e/ i! u- k4 ]CSS代码: _3 ]* g6 `3 j
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:3 O9 \' D) \, `
4 D6 K2 Q7 R4 \. H
% A% F8 w% v- H6 w1 o6.CSS带阴影和轮廓的边框) q% L4 t& |* K. V3 W0 l
CSS代码:
2 e3 `& T; w5 g H, a4 g- ~#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;
} 效果如下:
6 w7 {( l- X5 I& j W
/ t' i/ z; {8 k7 @$ [# Y' f
; {6 N t: e Z: `5 S
7.CSS少量阴影和轮廓的边框
7 j2 E6 Q. y- K+ c2 u4 z% SCSS代码:3 q0 e" H! `* J% U# |% X" \/ `
#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;
} 效果如下:
2 q: [6 w8 H* I
+ _4 M* D* h5 u" y% z J/ o' P9 @$ Y, o. H. @- Q8 L
8.CSS带有阴影的双边框
; Z+ s/ d, Z7 x: k$ {CSS代码:
}2 [9 Z+ I9 s: P- n* [#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 ~/ F8 y3 S, A
+ f! h$ R+ c4 v; f
; H4 B8 `1 z( r6 s/ d$ P/ m3 c
9.CSS多色边框9 S: d; v* f, u6 N% w
CSS代码:
9 R/ U+ @$ G8 P#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;
} 效果如下:
; g( B" j+ e. ]1 e
|