CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
5 i: o u. o% {$ E% `, x# p( b 以下各特效用的HTML代码相同:' W, r9 ~8 Y' Z/ e! [+ `! _
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> # X4 p+ }% y& {; c& r
1. CSS动画边框
% W1 g1 g; T, w9 n; D+ MCSS代码:
$ V, t' L+ A& [: `* V@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( Z! Q- u: T0 h$ e- U" V- [* ^
C& ? ?7 [: {" }2 m0 Z* T B" U
* ?/ M4 \1 q' A% _1 f# Q2. CSS图像边框
5 b. f5 g/ ]" K# m8 lCSS代码:
* Z& f& [# r) T4 B#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;
} 效果如下:: m) H" R7 \! c" c. c
+ t& t2 m) ]) f2 S: s! k d6 U- g$ [" J; n
3.CSS蛇式边框
! X/ ~9 O* P8 P( b# S8 j, QCSS代码:
! a! J( o: ]7 g# g; }#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;
} 效果如下:
& J+ [ D$ n/ C _9 \
3 p, N) `0 X" |! S7 S: G" m% H v, O$ n
4.CSS阶梯样式边框
r3 m4 I+ n. G4 j' O* f, g( g( ?CSS代码:" i/ k3 t: e# m: P$ I6 U4 k3 j
#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
} 效果如下:
' G3 x( z: R. B, ]7 {; F, H: s
{8 v8 C0 i' L0 |* _( X- x& @1 n$ R# A3 ~ P
5.CSS只有阴影边框
3 [5 o* n+ a2 N/ _1 ~8 I: D8 MCSS代码:
B; ~1 L1 q5 o/ F, Q* r* W! x#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
. x6 M+ Z9 V- b3 `0 a) Q b5 v
/ `+ z) p! M9 a) d N; y S) |3 S K8 l( c8 S2 |
6.CSS带阴影和轮廓的边框
& p- a7 b7 K/ ?- e0 O' B: mCSS代码:
8 r7 N3 `- }/ Y- H) ?/ u! _#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;
} 效果如下:# w% ^' t8 d6 z& W
( z, y, S2 A9 k7 _6 @7 Z% ^2 ^
" x0 e' |/ g8 c" H- _' X9 ^1 y3 b
7.CSS少量阴影和轮廓的边框
6 y1 W+ w5 t2 U$ UCSS代码:
, p9 m: Y! Q. `5 i0 D5 v#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;
} 效果如下:7 X( s1 P: B( D" \- [( q. W
% m" p/ |, a5 p
2 Z7 P; B2 Z0 n5 `8.CSS带有阴影的双边框
) v! }* l( H5 Y, m6 O g) hCSS代码:
8 q/ L* e9 h' e) v9 r# O' v#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;
} 效果如下:& z. r0 Q3 `3 {7 ^
% L6 v; s1 l' n- p+ p u
; J! e) [3 A3 v* J; e: y
9.CSS多色边框9 |# L% n/ T! A
CSS代码:
* k; n( T" x/ J#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;
} 效果如下:0 u, i$ }- f0 ]2 q8 t
|