CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。6 y& J2 `* A) ^
以下各特效用的HTML代码相同:# W `' @/ p+ S% t( _7 U
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> - K# \$ U6 t) Y( h+ {
1. CSS动画边框* l- ]! F7 D) U/ W. D
CSS代码:5 k; {0 G. b# ?1 R& d
@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;
} 效果如下:( l5 y) R- Z+ B5 d: b) A
2 L3 [; v# ]8 S/ n I0 O
& L+ L! o# e' M2 r0 j# D
2. CSS图像边框
0 X/ ~! A; I& f9 V3 q$ sCSS代码:* [) @6 F/ k, T" N- T% s+ u
#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;
} 效果如下:
) C: f3 v _& a+ P8 \. X* n
; E5 ^' k3 k/ o+ e. u" x5 L3 x$ i+ h! n
3.CSS蛇式边框
B; b( `5 x. \0 C0 ]6 i. \CSS代码:1 I: e5 z! C ?. `
#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 \, [' A1 ]6 s
6 E/ [. b% i( m/ @6 P" U- R
( H) P) ^8 V2 W7 T- O9 S1 T R4.CSS阶梯样式边框
$ u6 `$ H! `* E0 Q% t F3 I. ^CSS代码:
- t2 E( R( N; S7 w' f* ~* d#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
} 效果如下:* u5 V& }9 `+ z+ ~! b5 \$ G. {6 R
% U1 ^, M9 R! o& X
5 B) r4 d# ~- U5 _7 `# O4 J3 w5.CSS只有阴影边框: a7 p7 r# I# h$ v5 T/ S$ j5 D' \
CSS代码:
0 \* ^3 @( s) o' L8 R+ w. R) m4 M#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
+ L7 x4 U5 y2 L9 h0 E0 @% e
! j2 {0 v( A; O5 ?; a$ Z4 x
& n6 C, C' d7 ?4 z0 i
6.CSS带阴影和轮廓的边框
3 B* R; }6 e: M0 y* R+ UCSS代码:- Q0 Y" B0 O; \- b2 X4 @# s
#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;
} 效果如下:
$ G% G' _6 l' D/ K+ B" d
3 v( Y4 n( N$ J& E) K* m
: o# G0 |# ?+ ~6 H7.CSS少量阴影和轮廓的边框 H. ~& l H8 `) H0 |; h/ j& G9 [
CSS代码:
$ n$ x2 g# S/ Z+ ~2 M0 ?#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;
} 效果如下:! }7 u! d' A1 E
1 [. ]! _% h# N. r& |5 x" R0 ]: t' ~6 H
0 V3 p8 U" O! L3 ?' c" \
8.CSS带有阴影的双边框1 b8 ?" ]$ I7 \) T7 H
CSS代码:, i$ s V' ^: M' p S
#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;
} 效果如下:
6 k* E* |7 y9 C$ a3 x! h
/ m8 T* X1 v) D$ Z& g
5 f4 } r0 u! C. T- x2 Q" ~9.CSS多色边框/ Q! R5 A/ o: T
CSS代码:
* q- m# d9 P3 I) |" ~#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;
} 效果如下:
2 g8 J' _8 s; T* [$ e# }
|