CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。9 t1 \4 A0 Z0 m& q4 E
以下各特效用的HTML代码相同:
1 P3 l, {, a1 T2 z0 G<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> . [1 \ B$ O4 X
1. CSS动画边框
; d& ~9 d; s: H+ @; HCSS代码:8 b* d9 p) H1 u" L& ?$ P& i0 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;
} 效果如下:1 ^8 N: J6 L) }
' a1 m+ ~0 m$ d1 u4 S
8 m2 T$ |5 \; T' ]% P2 y2. CSS图像边框) ]. R) Z/ c8 C/ n) @
CSS代码:1 V' P3 p0 \7 L/ ]3 T" P
#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;
} 效果如下:4 x$ n- [' U: @+ \
) r( i. v' i' X) S8 _$ v
, f0 o8 ?1 X8 U; F/ i
3.CSS蛇式边框
) {# R5 W# J- m( ~% x8 j% G# [CSS代码:0 d8 E; o. |$ i
#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;
} 效果如下:
- Q8 L+ q+ D8 m% X) N2 Q5 T
$ C1 V5 @1 F4 s: [
0 p- T( ^# q, N g. m4.CSS阶梯样式边框
- @5 P9 h ]# I/ K% w RCSS代码:/ r& W* U9 {3 Q0 n7 g" F; ?
#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' d9 |- W! \. v- i2 H& w
4 C1 s) ]4 ~& }3 v) \% P5 j$ \) u8 v$ L) f1 f
5.CSS只有阴影边框: { C( b0 e, ~ o+ ]4 m
CSS代码:
& U, }! r. ]0 Z3 t; ]#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:) c: C W$ K) l. i7 j
; S2 S* w. ]) k( D" D
0 [: P6 A# Z/ Y. C: ?: [& p
6.CSS带阴影和轮廓的边框
6 P( g2 d0 X+ U) H/ C% B. j3 U1 U' OCSS代码:+ G3 u) n! }& g7 E& c W: |
#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;
} 效果如下:
/ ]3 I& b% o, Q- V: a+ q1 _1 x
5 ]. z0 K9 g, L. F
5 O! @* X+ j( h6 W7.CSS少量阴影和轮廓的边框& R9 w m! D: L5 J# \/ C
CSS代码:, F9 L; V! f9 p8 D1 q
#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;
} 效果如下:
0 A3 a, i9 a5 i/ j* [
! L- x- D/ G3 P) {
) Y( z: U, ?) F2 f k; L+ J& X: G
8.CSS带有阴影的双边框7 \. _ E( A0 R% n( E. l
CSS代码:
: M5 x. m% b; h' p$ e3 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;
} 效果如下:! ]! |; s+ n R/ T# A! }
C! Q: C6 K( k5 ^/ w. q
/ F7 A9 u& ]( [( u$ I9.CSS多色边框* o$ k D1 S( a' S1 E
CSS代码:
/ T% C( `2 j1 f D7 w#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;
} 效果如下:
! a- x! h( |% l0 J* O w
|