CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。: u4 ~$ \6 I+ u! D
以下各特效用的HTML代码相同:
4 q; _7 T0 ]# b& k6 Q<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 4 v4 B: s' V, i
1. CSS动画边框
. c8 q! u) ?! o5 C8 HCSS代码:: N2 b$ J* W# L2 \% d0 z9 h/ Z
@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;
} 效果如下:
3 i& f I3 C2 E' d$ ]( b; }) ~
) O1 [& o h$ l4 l$ T& c' y6 [
! h1 L0 ^8 w& _0 c0 Z2. CSS图像边框
% l z+ r6 ]7 k3 x$ h0 {CSS代码:7 |9 Y6 ]5 ~/ d
#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;
} 效果如下:) ~) J# Z& ]# Q; p' o
# d2 c* ]# |' S% @! m" u7 g
& f0 A- E& S; B; n' b" F3.CSS蛇式边框! l; s5 f9 O3 x$ T: J8 _/ r
CSS代码:, L0 x' l) ^- q5 U1 ?/ E3 s
#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;
} 效果如下:9 p1 m9 a, [- N9 [0 t" p
' m( i8 I; f2 Y
* y; ?" M/ i$ \* ~/ c! {' j4.CSS阶梯样式边框
- E/ j5 M$ V: ]7 N! l" p6 O7 m" ECSS代码:7 T% ^0 [0 _- P
#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
} 效果如下:
* b) f: b1 ]* F
: B: y2 n. q9 q
i" U0 x: y0 u. ^5.CSS只有阴影边框
' b, L$ v \& XCSS代码:
+ k7 i1 R6 X. r#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下: O. P' J3 q4 o' t7 k# b
! n- \# N: ]- R: h2 C% u, G7 z n& F$ Z$ P9 o
6.CSS带阴影和轮廓的边框+ n a- E& M; e6 C
CSS代码:/ P0 k* H" y: q/ z2 M/ 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;
} 效果如下:
, N; A2 l3 F; g. | W9 z$ n% l Z
$ ^7 r. M8 K6 r; [4 s# E- O4 L4 N2 o6 U+ l) q
7.CSS少量阴影和轮廓的边框' ]2 E& g3 M5 x$ R
CSS代码:
( u: w8 Y( j" b#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;
} 效果如下:1 \+ H5 j: w) L/ u
g, }" E7 k R0 R
* ]; ]% O V( v9 j2 r: m r
8.CSS带有阴影的双边框
' S8 ~9 e) }- _) i- jCSS代码:
) h1 U' n7 B4 @#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;
} 效果如下:
, \5 N( s4 m- I# K
9 g: c. ~7 A5 o7 Y, K: n" Q0 G# ~4 |( C0 m3 l( r# G
9.CSS多色边框* ]2 |; q5 e( q) D! x7 N
CSS代码:
O4 b# m/ u u#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* W7 L1 Y6 \8 w( T/ Z/ p' E
|