CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
k" H5 ?- k; e 以下各特效用的HTML代码相同:2 W- f G9 `3 n
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> / C# f" k P z6 f
1. CSS动画边框
8 G" A9 p( C1 ^2 I) Z* R: eCSS代码: Z& K1 [+ @( e# @
@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;
} 效果如下:- w; c% J2 A# Y+ Z& m
& w1 `; V9 E+ f& A
; h0 M6 O+ D& p5 Y3 ~2. CSS图像边框: H. A/ {+ v' T9 {5 G1 j6 m" q3 z+ K
CSS代码:
, J2 u8 A) s/ b1 S j#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;
} 效果如下:) l% x) I: l2 D! z6 { D; w$ e! c9 n
; K8 T$ ] B5 P" V: n
% }. a" g4 K I$ ]! _# w3.CSS蛇式边框: M9 a; M: E, u5 R
CSS代码:$ ?0 F+ n, \3 h' q" y
#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;
} 效果如下:
% X5 V: |% T7 e& c
Z2 ]9 P/ \7 m1 I/ [8 f0 v8 z+ c' X8 S; q) b3 H, P
4.CSS阶梯样式边框
; [% k( G0 X" C5 [% e' fCSS代码:4 G) `3 u5 p1 i
#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
} 效果如下:
% S" D3 ^$ V- X( c
3 T& g: S+ w/ X h9 X# O; |5 j
7 w- N1 t+ K" Q/ x6 z8 h% S4 f
5.CSS只有阴影边框' \; ?. ^2 x" w: D
CSS代码:' n% D2 j+ l1 N5 m& I. B! i
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:5 w4 Q. Z) |/ X& B0 Q8 b
s* R/ a. E6 m! L7 r. h) t7 U" R# o5 |+ ^* c5 w2 t) b
6.CSS带阴影和轮廓的边框4 @0 b7 e! z& C) |
CSS代码:; {' l9 X. e( J6 s) R6 X
#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;
} 效果如下:& R, `- `$ g7 D" V
. W1 @2 R4 z- z& ` m: s3 X
2 b! `, _' q, _' Q4 |$ { w6 t7.CSS少量阴影和轮廓的边框
5 I. x! u$ R0 G$ S( A) U7 m, rCSS代码:! f. |- P ^: k- v4 d2 E+ K) R
#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;
} 效果如下:
5 d2 ^6 a/ r1 C a0 V7 o0 Z
: ?1 X4 V' {5 X/ d
. ~0 i# J# ]: Y$ {2 L: ^, v3 E
8.CSS带有阴影的双边框0 `+ ?! L0 D+ ` K
CSS代码:) `, B7 T" Y( Y0 h$ T; e
#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;
} 效果如下:
/ U5 L9 H; X' h9 }" y
7 Y6 a, I5 c" I
$ C( f- k; P8 ^$ {8 H9.CSS多色边框" b# O: P' |; d
CSS代码:
8 |8 v- Q: g5 R8 ]7 Z: R#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;
} 效果如下:/ D' `) X$ U, p
|