CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。 s% A+ g) e9 x# E0 {" p5 U
以下各特效用的HTML代码相同:
! @4 p2 @' P8 E# ?<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 9 C5 y! i/ b- ~* O1 U% Y+ s
1. CSS动画边框
: {! g4 {4 E* z- ?6 L5 b, {CSS代码:
7 f1 Z" b+ F2 ^/ ?) K; 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;
} 效果如下:
0 G3 X/ E1 I% y& ~
5 W6 H( f2 @3 \, G
8 w, p) M+ \! D, o
2. CSS图像边框5 W% H0 g/ ]2 T
CSS代码:
9 @7 F/ k0 K$ e0 e" t. `9 S S) h#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;
} 效果如下:
. f C5 |( h7 [8 K
. q. ^$ }+ ~6 I$ p) T X* A( m2 W/ T Q! M. {1 E
3.CSS蛇式边框
$ r5 e! ^( S& O3 D3 F/ D5 oCSS代码:* z+ h9 n1 B* V F. N0 Y4 j
#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;
} 效果如下:
8 N# _7 N4 l# _2 }" {: F9 X
5 A8 ^9 q3 S4 O, J- i/ D
' f) r9 G- k( h
4.CSS阶梯样式边框 Z) x" J7 p- W9 ^! m0 ?3 o
CSS代码:9 {& ^ f7 O) U" N7 u+ E
#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
} 效果如下:2 `7 V$ Y' C1 ~& V: n3 [
2 J. M8 W) P/ C* g
4 d( \. I' f7 @5.CSS只有阴影边框
) i( N- v" n4 q. y6 ICSS代码:
+ @$ d6 D4 _# I# D$ M8 p- w1 k#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:5 r' ?; Q4 U6 K; u! |
& L2 i( h% [8 x% @ u) p6 B+ N- b5 C& {" ?
6.CSS带阴影和轮廓的边框 k9 ^1 l h6 v' {: i
CSS代码:& N( Q% U @5 S+ S% J
#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;
} 效果如下:" D- ]3 x$ @0 z, L- w. I G
+ P0 ]0 O4 I+ w7 o8 q& t
# I# K5 c) l9 n- U7.CSS少量阴影和轮廓的边框
# K; w! B1 E1 l* F2 d! [9 TCSS代码:
0 b' \' R' h% X* |/ ^#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;
} 效果如下:
' J. e" \( U% F W
3 j) d5 R& t, Z* n( m; K9 E/ T6 D) h
5 E" R) h, V9 `3 Y8.CSS带有阴影的双边框
P! a5 G1 ? g; n; h$ pCSS代码: d; C* \2 A+ U/ }
#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;
} 效果如下:
. U+ v0 ] Z% I7 s- P
" a& F+ X3 l" c# T+ a& i- x
* M! o$ P: B" P/ u K5 r9.CSS多色边框9 O% c( r% v, S6 u- k. w
CSS代码:
* w7 T# v9 |% ]* n7 ?#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;
} 效果如下:9 `8 N* u& S, T5 S/ l! r$ `
|