CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
9 s, _1 x6 ^% l/ ?2 C, ] 以下各特效用的HTML代码相同:
4 {! p7 V" Q! K' j, ?2 b<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
- g% M( D8 S) C1. CSS动画边框
6 o3 M0 K% Z* O; D# dCSS代码:9 l* o; ]3 R1 G) X5 o! L9 g a
@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;
} 效果如下:
! ~7 F% ]5 ?, o
4 i |% D3 y, j, C. O8 h6 L; i5 t
9 {+ A% s1 Q4 A, d" Q) {% l5 l6 a2. CSS图像边框* e; `2 x% p8 ^ g/ n7 {+ X( [( R
CSS代码:- [$ J9 O) u 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;
} 效果如下:' {7 |8 D8 {! x# ^( k" [1 t" K- C
. L! e3 u ~6 W# ], Y+ a, v
$ b& W7 N" R h- y3.CSS蛇式边框
" u$ u$ p9 S% o& ^CSS代码:
9 _3 q6 y) f% g& {/ {8 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;
} 效果如下:$ J) ?+ M4 }1 G) z+ r0 t
1 m; K o K; V# u# s1 H% J9 h5 t1 Q
4.CSS阶梯样式边框1 f/ @& C7 Q- g: H) T5 j6 F3 X
CSS代码:
4 f* }8 @3 h$ e, W0 }5 u& 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
} 效果如下:0 y# I @6 a" ` ?4 I
) q0 G c5 s. @1 N' d, t
+ O' L/ D4 n. l! D# B: U1 X5 @& p5.CSS只有阴影边框
# q1 K, r |/ E4 s* YCSS代码:5 i' @# _9 n" F4 I ?0 P. ^) {4 T6 a
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
0 _3 l9 U) Y; i. Q6 g" o
: j7 M L: U7 R* A
: q7 H) _2 p8 r% R4 ], f d6.CSS带阴影和轮廓的边框
' A' s( `2 f; UCSS代码:
" v0 s% l+ w& H5 [#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;
} 效果如下:) `* p, v! a, z5 k4 w
i8 V) l$ [3 ?( s/ u3 o6 f
( D5 X! f/ ?( G$ z6 y: U
7.CSS少量阴影和轮廓的边框
6 @4 k; y* g' dCSS代码: K+ ]9 E/ Z5 C2 |0 @* Z5 ^
#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;
} 效果如下:% G i2 c7 |1 H
4 U+ j3 f; G: U; ~5 E& S3 c
6 Z$ W0 \3 V, O: {, F: J+ \8.CSS带有阴影的双边框$ j* d) c' n) l0 [! [: Z' P
CSS代码:" e& h% ~2 z. n4 o/ O2 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;
} 效果如下:
7 g. r6 q- {& ^/ z7 @/ s/ ]
' M: l% Y K! p
2 J: Y% ^" N; S7 a2 U
9.CSS多色边框. n9 H! \6 N$ A; C( U
CSS代码:) ~) [4 t& a0 G
#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;
} 效果如下:) L) X- X5 K* P
|