CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。: o+ u6 a6 i3 q L7 [% w
以下各特效用的HTML代码相同:/ J$ D8 j) M1 e$ D4 b4 F
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
1 [- D* x$ ^; {. t L1. CSS动画边框' Z3 V+ j/ E. L6 O \
CSS代码:( _0 ^$ ]$ c4 Q \* Y
@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;
} 效果如下:; \; V/ `! u5 n2 r" X& ]
: p8 q8 o+ F$ B
o- v1 w" U) L/ z2. CSS图像边框
4 P1 ~; V8 O7 T5 UCSS代码:7 C9 M! E4 x: M/ Q! N9 g
#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 y$ j6 I/ }, |8 ?0 A; x ? r) b
- y6 a+ K+ B4 y1 i
4 d2 \! ]5 d, s3 |, T p7 t3.CSS蛇式边框
' M+ v! q3 Y8 Y! ?9 m+ ~4 S4 HCSS代码:
9 o& j. R' ?4 C8 b) 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;
} 效果如下:
+ ^2 Y3 {) d# E" |, u
7 ~: ~9 p8 ^& q3 T2 b
9 o$ c8 n3 G2 Z) F4.CSS阶梯样式边框1 z8 `8 b2 Y" y/ K
CSS代码:
) h, E. I) F; W: p. R#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
} 效果如下:8 {' t! T$ [5 x5 e* O
! b" d4 X: J$ C; |+ h* E; T2 I! I# f+ C; B8 \8 p, i
5.CSS只有阴影边框+ r' h! q6 X2 u8 l1 J: {, [: }
CSS代码:
c7 _9 S! y/ _4 u4 [#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:* r K: x" }; f
5 Z5 I6 j' }' D, Q& X
3 x' t, k& D% V2 M6.CSS带阴影和轮廓的边框
; w/ @6 \" v1 Y, R. ]CSS代码:, c1 N+ N2 H+ }$ ]
#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;
} 效果如下:" t) _( m4 K/ o$ s w% ?
0 R3 G7 A1 w; d
6 E% k6 v [ q+ v; S% \& h7.CSS少量阴影和轮廓的边框. ?2 r& L" r. M2 D
CSS代码:
; r: L# I* I7 U, m* R& Y#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;
} 效果如下:
# L( k' c- B8 ]/ ?( h) M [
9 A- V. G/ }9 ]- b
4 ~ B2 M8 A9 \2 Z# p$ H8.CSS带有阴影的双边框
+ C& a/ y$ Q1 x. q' a+ k% BCSS代码:
* i! ~/ C- W1 h# p5 v$ s/ Z# x#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;
} 效果如下:
& I3 d" k: f# {) R
; ?* c- M( z& g7 I4 j) |( ^
/ {5 [5 ^. b# M- v9.CSS多色边框
' J* Z# e/ ^& mCSS代码:" E8 ], ? G9 e5 d
#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;
} 效果如下:
5 E! U( H9 t0 ]/ r
|