CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
+ O: l. y: U$ H- \ 以下各特效用的HTML代码相同:3 p* i: y& R) w M9 h
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 1 ]2 m7 a+ k0 y k* |
1. CSS动画边框; ?3 g6 O T, ]
CSS代码:
8 H2 o1 D0 D6 Q$ C@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;
} 效果如下:' B: n/ m0 I, L! ]. x
( Z6 g3 q% Q3 j4 l! A" P# K4 I
* i5 d! Q! x8 m3 G5 ^0 Z+ Y
2. CSS图像边框4 c2 C6 B# o- U
CSS代码:0 U+ @% H3 ?& @# ^" d. r/ n
#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;
} 效果如下:
7 l& N% w9 M; ]
) \+ F7 x& L7 A( S/ |" N2 G2 c; Q
8 Z% Q* v! j- a3 L q3.CSS蛇式边框1 Q! D2 i; P: k1 F8 U+ D
CSS代码:7 \$ [& U% |3 S7 z2 ? e
#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;
} 效果如下:+ E! S5 O0 T7 u# {* J) T
: _& z" S" }# q- X2 ]
0 y* j8 ^1 A: M- E$ {4.CSS阶梯样式边框1 r' f* Q" \7 x" T& P2 ^
CSS代码:4 M* e9 D! _" K! H, [; W1 {
#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
} 效果如下:
- G7 D& x, c: W) M
# q( J4 _( b7 m8 A
& d& T+ t/ R& q8 F$ X
5.CSS只有阴影边框5 b$ p4 B8 J) N" h ?- l
CSS代码:
* C, S5 f1 M! r7 p% 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;
} 效果如下:
$ \4 B. L' `5 Y8 |
2 w9 i& t/ c9 O* |, g
9 Q- h; y3 z) n) V0 U; S: o" [6.CSS带阴影和轮廓的边框
+ F$ q. ] C' ICSS代码:
2 \9 p/ \1 o' o G) m2 i* A) @# N#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;
} 效果如下:
( e7 C7 ^# H: d; r6 M7 X1 a
/ _. @! t% L! H" x
e: |; V7 R. l) Z5 I& E6 ~" W3 Q/ F7.CSS少量阴影和轮廓的边框
t2 X( M8 Y$ O, p% V! jCSS代码:
7 ?2 L5 I9 B( S! G" ^! G$ m#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 V2 d2 `7 j7 w2 I, C" P
- o% E3 p, ]% X+ L$ g
1 v h- J s5 I W7 F8.CSS带有阴影的双边框) t5 s2 [6 ~7 K& _- \" G( _
CSS代码:
2 ^+ _1 }4 s7 j. j#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;
} 效果如下:8 i9 b8 ~( [" t. R0 y7 c `
) A N1 m( X# w# \ A+ r9 j; x) r
+ r* `+ i6 S% I. S' ~9.CSS多色边框
: J6 u! t$ }+ O3 D" Q% d5 ?, `* q$ HCSS代码:
. I0 I% Z6 q5 g0 A: @: I! t#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;
} 效果如下:
. B3 y& Z9 Q& P
|