CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。. c+ U8 G% ^5 z5 ?) r- j
以下各特效用的HTML代码相同:
0 p0 r" y, f5 |8 h" \9 b/ u* k<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
, [! O8 z% Q) N1. CSS动画边框
2 n/ {, B( @ |8 i; wCSS代码:2 ?. `4 J5 w0 X9 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;
} 效果如下: C" b; [ u4 Y: F2 x- @
; m" b: X p& W5 m! o6 A
0 h3 v: F. ?7 N t. @2 Q& m2. CSS图像边框/ a5 }! Y" K2 E: U/ j
CSS代码:
$ [5 \( A$ b S. X/ D( ` L1 j#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;
} 效果如下:3 s3 q4 E0 _. F( G+ e# C! s$ d
, c' }' c. K' `. m, a
2 X3 K8 q! _- d
3.CSS蛇式边框9 O- \0 S5 T7 \
CSS代码:
0 ~! _7 M( R' r# s 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;
} 效果如下:' ~: D7 _ X. n- f
8 v* l/ r' T& i* @$ P _3 Z' ?" h
. j8 u7 `4 ~* K) z, W4.CSS阶梯样式边框
! E9 ~6 {# r1 F- _ ZCSS代码:# k1 ~3 |8 P4 w4 L7 p3 `
#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
} 效果如下:
* X! c( s7 ^7 U4 |! i- \
$ Z+ d, B3 f. N i$ e" _ b
. R; X0 y! K0 j# _/ R- t
5.CSS只有阴影边框: G8 n( S. o8 [4 \$ s' B6 W2 G; L
CSS代码:
: N" W0 m- I d4 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;
} 效果如下:( |/ r( d# J" R0 U
- J/ M. V) R. \! D# h# @& S
. M% c7 x- h/ H# [' C0 g& K$ P" d. N
6.CSS带阴影和轮廓的边框
8 w3 n$ X3 \% H' R1 wCSS代码:/ g( N0 X1 e! [; d; 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;
} 效果如下:
& L% \6 c& D5 @1 L
* z# d- t1 N. |! G
. q1 P0 Y* g/ L6 M6 k7.CSS少量阴影和轮廓的边框
/ m `' A9 I! ^! h- a+ g% K9 RCSS代码:5 i+ Q$ \& n, Y, U8 c% N
#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;
} 效果如下:
) T U9 ~3 J( ^& ]; v. K' R! A
/ I8 K7 F' m ^6 O! q |
( M2 c: F. }1 {* b- w9 ], P8 ?8.CSS带有阴影的双边框9 j$ [& u, i* q0 a
CSS代码:7 }# K5 p1 m; M3 d
#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 P/ `5 ~7 N% E/ u* g
) `" r. b: N8 t# B
9 |8 C; {; r5 G3 E; k! N9.CSS多色边框' F) a' H6 O% s! _. s) o
CSS代码:
5 g- n& Y1 C0 B4 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;
} 效果如下:
7 Q$ e9 ~& A" o- B
|