CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
' {: z, O% y+ |- {% c; j7 \1 \ 以下各特效用的HTML代码相同:
- x( h: P- t3 N, ~; v" b1 y<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> ; F& |2 J9 ~8 M; `( n4 K8 {1 F
1. CSS动画边框
5 ]" l9 h \8 V% N$ ~3 c \CSS代码:
, H H- a% |* A& L@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;
} 效果如下:
3 S2 i* p. ?9 j8 x( h5 _$ Z% o% K
" G2 N2 m. q% O1 R( T, Q4 {8 c" m7 G% N- }3 N
2. CSS图像边框; C0 O' |. m l( \3 |3 c( ?
CSS代码:( I- u2 K3 e* I1 `7 @2 c
#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;
} 效果如下:
) ?+ M+ u- d& @0 ?( Q
9 @$ @9 o1 w3 ]2 C/ M# Y' J
( l( O2 K+ |% L& I# V- H% j4 \& U, q! t3.CSS蛇式边框
: s) |" w3 Q4 h" a( H! E3 g- rCSS代码:/ X) W. a* }# v5 f/ g
#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;
} 效果如下:% f; b( Z; O4 x3 X- d& g
' b! _0 c) l" S; x% y: d% K* s
6 H/ U* @/ U3 C: \4.CSS阶梯样式边框# g s, \- j) d# E) X2 Q; s* D: F
CSS代码:, @# G& g: C/ g: j& `1 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
} 效果如下:" E' ^3 V: @6 }+ C/ A
. e0 u- R, ~7 }8 }4 P4 U/ h' T
+ _% y$ q. c ~3 n3 a' ^
5.CSS只有阴影边框
& Z( w+ _8 J8 J0 ^7 j# K8 DCSS代码:9 S/ ?, b+ \2 }9 L! r8 v. d% Q- n2 {
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:1 D2 C$ e& [7 K w% X$ n9 B9 T
2 B# s i( k2 [6 z5 K4 Z) [( @7 I+ G8 Q. u+ F' x1 z1 |
6.CSS带阴影和轮廓的边框
& M( l R) U* m$ kCSS代码:
* G! e! L# Z r l6 Q5 F 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;
} 效果如下:
6 ?0 G0 L9 `/ y! p$ A
0 S# K @, K3 ^! ]1 |
5 h; Z9 g3 u# `7.CSS少量阴影和轮廓的边框8 V: A) F- P1 ?/ {( e4 b$ m' W( V G
CSS代码:
& [- Q8 m8 d! p" ?2 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;
} 效果如下:
. i6 i( Q8 [) G: J% E( B9 y% v
0 p3 [# M; ~( [1 H( p: r( i7 ?2 W/ M$ e
8.CSS带有阴影的双边框
2 ]! c* n& X7 T/ ~2 f/ GCSS代码:% [2 s, R* S4 e* W3 k: T8 @
#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;
} 效果如下:
' I, B# H% v4 t# O, f4 A* i
# F* s; `% S& \/ E( c
6 P! K3 G2 ~) P# r4 `9.CSS多色边框; i! D+ _. x- B7 B( v7 z u
CSS代码:
R4 l) H/ F6 V+ b7 H6 k; b#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;
} 效果如下:1 ?+ W& X8 Q4 @1 Y8 n. {
|