CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
' P# \. K. f. n& U, K" j/ b 以下各特效用的HTML代码相同:
& C7 n2 H% s8 [- A9 P<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
$ q s* [7 _, E1. CSS动画边框
2 F& t. W o* j) L2 x6 I/ PCSS代码:. q# X# B& P+ \! F$ i Y0 p
@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;
} 效果如下:9 i Y, _( J P) Q A
' l$ O; e' b) D
( |" s% I( c `% F2 f
2. CSS图像边框
. _5 f8 A I' `CSS代码:
- O/ ?, s) F a#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;
} 效果如下:
2 @; O( _* ^3 w* U" u
; C: H2 G4 @: e: e+ m
/ u$ }1 j0 q# `; M6 K" i" Z; V. s3.CSS蛇式边框; `/ a' k- d- O5 B
CSS代码:, X4 k: `; K- M# K
#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;
} 效果如下:9 Q3 D9 I4 \: R
- q3 d! T+ C) q( N# y% u, @
+ d d1 d3 ^# ^, N' ]
4.CSS阶梯样式边框5 C0 w' t" n. o" S# E9 u# b& k
CSS代码:7 E4 e0 }' j1 E+ h
#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
} 效果如下:
! C6 s1 |0 _1 ~& c/ S! Y
* u+ @4 q; l% e9 [+ |5 j
5 S( c9 D2 q8 Y! Z" b5.CSS只有阴影边框
. D7 ^3 E9 S3 YCSS代码:/ T5 b/ z; h$ N
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
9 _. K( S1 y/ E( ]. s x
# p2 N% b! {) N& F8 ?1 c
+ k t/ K# e: [1 I4 }+ y2 n4 o6.CSS带阴影和轮廓的边框! h, F5 X. g# _! B
CSS代码:; [. G2 B5 j" e* q5 r
#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;
} 效果如下:
v; q1 B4 y7 s5 m" r! i+ Y; ]0 v
. K: n" N O4 ^6 X) h5 R6 A I, {3 ?5 U3 @2 i
7.CSS少量阴影和轮廓的边框
- o7 @& A4 [' z7 x7 u2 iCSS代码:5 @ E z3 @* f. C! O" C1 F: e- t+ c# o
#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;
} 效果如下:( c7 D8 U4 v1 _! `% [
5 p; p9 ^5 r! t% b* q
" M; f6 ^! Y- h C
8.CSS带有阴影的双边框; `+ J) T$ d2 H
CSS代码:
4 c. j5 o5 }/ M- J ~0 ~* Z#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;
} 效果如下:
" v7 G) w1 _. K5 q' c6 B
0 ]- {5 y( Q# }# X; f0 }% ]. ]% D# h5 X1 m$ X- b
9.CSS多色边框
( \) A3 O* m0 o5 @CSS代码:
X# G5 u1 H0 u- x$ J#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, z0 X6 c) v; `
|