CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
% M. v3 E/ G2 v$ z0 m 以下各特效用的HTML代码相同:
% h" {, d6 {8 T% N4 G2 r4 D<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 8 c1 J6 O( `, }8 k `- t
1. CSS动画边框* z- h% l% y7 J4 ]" D: L/ `
CSS代码:
) ^/ ?8 J0 ^9 [6 b8 O@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;
} 效果如下:$ |4 k+ Y9 P2 G; M
5 c3 J9 P' A, u
) E# L" s9 }! k, @9 b
2. CSS图像边框
7 F3 M7 d4 e. ~: Z6 QCSS代码:" q# e/ q) w; p$ U: y4 F9 o# 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;
} 效果如下:
9 g1 w7 ~2 T9 B
q) ^1 N- C3 n9 W
1 ^, A8 n: L7 y% [' h3.CSS蛇式边框% N- i e0 H* }7 }# u# L* ~
CSS代码:
7 L- T1 W8 A( R% X7 m, Z#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;
} 效果如下:
: t$ w' f9 a9 p+ g
2 i- q# G4 Z( M5 {
2 `, D3 R. W) L% {/ {" Z% ?4.CSS阶梯样式边框9 K/ r- }) b. I+ N
CSS代码:
6 x5 J" A/ f0 n; e; 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
} 效果如下:0 ~/ R+ o: S4 Q7 `& A5 w2 [
' D, z8 }/ T0 z
. t0 a% @- e/ c! w, Q5.CSS只有阴影边框
* R5 m! l2 \' ^# c# j% ECSS代码:+ ]2 x5 y2 C! K7 O U+ P1 J
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
, n/ S* \% |4 D# B! O
" F6 ?$ Y8 Z" K u8 i1 u. x
# `) o" m& p0 X( y4 I7 T
6.CSS带阴影和轮廓的边框
; i+ Y0 b: H7 @) K6 R" ]CSS代码:
; |; Q2 r2 {+ U# Y# ?$ P#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;
} 效果如下:' i/ L% e, p9 T- o/ o
8 e# d. W1 D' T/ I6 t; n- C" J
1 J0 S2 _# n: ?5 E% e& y
7.CSS少量阴影和轮廓的边框
2 y" H# r) X, U0 kCSS代码:( _* b" M5 O/ h, k2 c; ?* Z
#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;
} 效果如下:
5 s0 }7 W/ \9 Z3 H# E3 S
% q4 ~, t( \$ z, P
0 X5 ?/ |- A C3 {
8.CSS带有阴影的双边框
0 j' Z, H: ?% k9 t7 N; m7 rCSS代码:
! ^1 w1 I/ _$ j* i1 U- _#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;
} 效果如下:
- a% ~2 f8 X4 K0 m2 b* c
5 H0 `! W* V x+ M1 K9 F+ u2 ?$ U
6 J3 c8 }' Q2 [6 Y( i% c' G) Y: b9.CSS多色边框' Y/ @- I7 c! O# R
CSS代码:) E4 Y3 M9 M1 f. q: i8 a
#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;
} 效果如下:
* |+ x; F( E; x1 f& I8 U3 V' t" ~
|