CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
; C2 a; p. P2 T4 i9 {$ W 以下各特效用的HTML代码相同:* t$ {' j5 a: f
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
' T3 C' K( N- T2 W1 s4 y, ]' @1. CSS动画边框
! m7 X* X2 F( w7 m/ dCSS代码:
* E+ d1 `6 D+ s# K2 V }. |/ e$ b t@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 _7 Q. `) q: z' W5 t
3 ^2 `4 ~6 z& O8 h! \" `, R4 I& g( p, d
2. CSS图像边框
$ g( W& w' ?; C: @! ~8 u' }CSS代码:
! P. V0 P' p" V3 B: B( v#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;
} 效果如下:5 k2 d8 k: W# H6 k: S+ k$ R
9 e6 T- U3 A. e# D5 J! z
$ `8 U9 g# m s+ F) N! E9 v* C3.CSS蛇式边框
5 Q4 Z2 U8 v* C+ n, M+ zCSS代码:6 M7 ]' {& i% F! n1 O% z6 e4 K
#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;
} 效果如下:8 F; w& S5 D% Z* Y
7 j! A3 ?) O2 h7 `3 V: O3 ?
8 `0 p0 n/ B; X. o4 m4.CSS阶梯样式边框* a% x7 q8 u% E: M. E# v/ b
CSS代码:
2 ^: m) C3 j3 w: n#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
} 效果如下:
- q/ ^' }% j; \% ?/ n
3 S9 g) Q4 N7 E, z/ a. s# L/ {; }2 j
5.CSS只有阴影边框
1 J* n4 b z: k* V# J6 yCSS代码:
) e. p8 P3 ]" q3 h9 d6 ]" ?#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 f, i* b7 S/ T( d5 k0 [
6 ^- ~6 U& y+ m7 J# c4 `9 F. E
7 P! F! J) g- C7 ]; x
6.CSS带阴影和轮廓的边框. c% Q6 y) r) E3 c
CSS代码:
' R" L! {& Y: K8 x9 t1 O#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;
} 效果如下:
- l. O# B) |/ l8 |8 r: x
% r8 q( x0 f9 a i; j/ l7 o
3 U: c( V. F; M7.CSS少量阴影和轮廓的边框
4 Z% I2 K$ _0 c( i9 n0 NCSS代码:2 n3 k- N% n2 a4 |
#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;
} 效果如下:% u7 w7 |& ? {' `$ ?2 u, o( P
6 A5 b0 B) Z/ q9 D4 W) b
. m4 I& H2 r3 ^; P6 S$ m% W
8.CSS带有阴影的双边框3 E/ g* R8 J) ]* K$ m1 N
CSS代码:
. D" J1 w) K4 W5 m8 K( f& K#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;
} 效果如下:
- m8 d0 r: Z! v/ w
2 @1 [2 V* {7 O( g) W& c- v
5 ?# s8 n; G l) _/ I- [9.CSS多色边框0 P( M& v. b2 L; l! V5 p8 X5 h
CSS代码:( R# `" z! P7 ^+ f+ X: S3 g
#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;
} 效果如下:; L; g8 |: q' X% X- c! \
|