CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。 u( D3 L( B9 C9 ~5 |
以下各特效用的HTML代码相同:- Q' g s$ p7 Y9 u
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> / i7 Q) }; `. Z+ N/ r" T
1. CSS动画边框" Q6 \# g* [! E
CSS代码:# x( a0 d- I- d2 V$ T% h: k5 t( j' B
@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;
} 效果如下:$ O, B9 z2 u/ V6 N( r
# V1 y+ W3 |) X$ s9 ~& A. l% j
" B+ Z7 a- q0 k; c+ E$ C* J$ C2. CSS图像边框
, m# X- G% t( F. x7 J) oCSS代码:
8 J. c, `: k; e- ?" _$ \#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;
} 效果如下:
$ `& w/ r) T& ?$ \# R
. v0 x6 m+ ^* u
& F* v/ i' n, ^' j6 N$ E2 P% k2 d% J3.CSS蛇式边框
/ {8 |# L" y0 w. g- m. t6 UCSS代码:# G h9 m3 s. d7 B* y+ t3 X
#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;
} 效果如下:
1 C" }: c, U/ ~1 A# d0 Q' _+ Y1 U8 b
& u+ Q+ M+ s7 v, e# w9 U
" l0 o3 c3 B, ]3 N4.CSS阶梯样式边框& A) f5 S8 @1 L, }9 ?# H6 e, K
CSS代码:7 }7 ` G8 I; d7 R* I1 t- d8 h. V
#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
} 效果如下:$ B9 N; @* E# C) Z( g
" O( k! N% N; \. q6 I3 ^4 T2 N/ \3 Y3 f# A! ^
5.CSS只有阴影边框& j; P7 Q! W5 n2 Y) L W6 R
CSS代码:
. T4 K' D* t) y6 v#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
! b3 }7 z% L/ `
- D, g. ?1 C2 t$ y2 v5 ~, U$ y' _. J: y
+ c R; m+ k9 L; B8 Y. y7 F
6.CSS带阴影和轮廓的边框
2 k _+ @' s; z3 ]+ iCSS代码:/ b( Y8 X* C e. [9 a$ B! e
#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;
} 效果如下:
2 p1 H% Z% ~& T
& H# q$ Z0 h- y3 Y0 D0 a, m! H# G1 Q' ]+ t* ^$ P3 y! I
7.CSS少量阴影和轮廓的边框4 ?( U; h9 N5 c- O+ Z: x3 Y
CSS代码:
3 a5 f& _" e& t; M' ~' W( d#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;
} 效果如下:% H+ ?2 q( W2 J( {+ w
4 M7 p: r, {! p6 [" q8 |- i( e% K
+ r9 {9 B) ], `4 G- d8.CSS带有阴影的双边框' k6 g+ `0 ~) W$ d$ }2 O
CSS代码:7 k( @1 k3 m2 H$ f9 s0 {
#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;
} 效果如下:4 f) b ~, M0 }; P
2 ?8 b5 r5 o i8 _1 }# L2 E# r8 E
Q$ g6 e8 @; ~9.CSS多色边框* N8 m5 D* x8 `/ ~; j
CSS代码:
; M/ I/ H, |( r; s#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 E* R7 S; r
|