CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。" D x% h9 y T0 W
以下各特效用的HTML代码相同:% g4 p L; ^+ m" H- _
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 0 a' v3 t. t, M4 }& c: S
1. CSS动画边框
% v3 O1 A" i$ UCSS代码:
, E( r& x+ i. j& K" b, _9 ]@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;
} 效果如下:
/ m9 L( }: j" H# o" \/ r
* u3 {. ?7 A5 z# R* x/ `! d
' z3 {3 m+ w0 j$ F
2. CSS图像边框
. a5 b4 z+ c+ `CSS代码:4 n9 k! P d: ]% @+ c! O' ^
#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;
} 效果如下:
4 [0 {& [1 d, ~5 ]+ n
. Z4 ~! w* z$ j) \1 o2 h
% {7 ], B4 T3 d
3.CSS蛇式边框
+ \1 I8 b! r9 d0 T' d( XCSS代码:- {& N$ N" R9 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;
} 效果如下:& v, ]; Q9 S5 N; X' U9 G9 `: ?% g
, [ e/ N. j; _3 `' p) H, h9 U% T( n
7 `8 k B! ^# j0 ?' E4.CSS阶梯样式边框
( J# ?8 H1 r3 z/ \CSS代码:
* Z! t8 U j7 n: A1 a9 O#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
} 效果如下:' a2 d7 N. E( Y8 f
: W& j( H! K. ~% P8 @
5 ]# W1 z( j6 o& U* P6 P0 P; m9 {" U
5.CSS只有阴影边框- t9 n" Y; ^0 `6 S2 s, c: T
CSS代码:( u9 q/ z! {$ q$ O
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:- r& R' q5 o( a" n9 B! C
1 v, ~3 `7 P h9 e1 W3 L5 R5 \6 l' @2 t/ f) b
6.CSS带阴影和轮廓的边框
* R( C% N- z# i. t( ~CSS代码:# U0 D$ W6 @& [/ o: Q
#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;
} 效果如下:
) |* \$ ~/ J( x$ c0 f( ]
. |8 a' g, G; P* |
2 b8 a! S/ O+ E) J7.CSS少量阴影和轮廓的边框( c8 `/ Y u" V! H
CSS代码:
1 H6 n" |& ]* W# o8 |6 o L#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;
} 效果如下:! ~% T. L: {# B8 V7 r {+ s9 B
2 C8 j0 ^' D: F/ l0 f7 {
/ u- o. q# y( Y: L8.CSS带有阴影的双边框
6 k; K, j8 \. k; X0 ^' J& CCSS代码:+ ]! Z4 P- {# [/ ]. f
#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;
} 效果如下:- a$ V: c6 Y4 B$ Y
% f0 Q. e! o6 b2 g* B: ]- q- u3 J0 E# s2 E# f k
9.CSS多色边框1 P$ _4 Y: A$ K' q/ S
CSS代码:
! J) g& e7 g% f: X#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;
} 效果如下:, \" p" X) O! g9 u, h+ H
|