CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。$ h( `) `% c. Z0 {( m' @, a, F1 u
以下各特效用的HTML代码相同:9 q5 T0 I# k% ^
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 6 ^% O2 r, I- e$ k# k/ Q) v# t
1. CSS动画边框7 u& a" |) F0 K( x% R( A
CSS代码:
' o+ T$ f/ w7 e4 L+ @$ @$ O( D& o% I@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 H3 q4 {/ _* ~3 _
6 ?' P* v! h: Q6 ^' f/ N; S
1 ^: A) M" m1 S' d, m" \2 B
2. CSS图像边框3 _% Z4 s$ Q' J) K
CSS代码:
4 I; W2 S' w p3 D% u4 y8 V$ 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;
} 效果如下:
2 K3 U" O! a0 @, X
- V' V' @* u( g4 q P/ b- [
9 ~& J3 [0 O$ `4 d9 i
3.CSS蛇式边框/ v3 U4 _3 p4 d+ U# m- Z; n
CSS代码:# @% `4 d: `- y
#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;
} 效果如下:
7 I7 X& }/ f- W; z1 s# Q
& q9 i( w& y" o% x( ?( u
2 R" [$ |5 @. A. H/ \ f4.CSS阶梯样式边框
* Z9 k! |! _1 }' g3 I: d2 GCSS代码:" L( ^. C0 f N* j4 T3 ~' A. z
#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 z( P/ r& L
6 u) a% Q2 R: [* \" {: H4 S1 Q; i7 B
- d( \1 F3 N [2 ~# o4 g6 j* m5.CSS只有阴影边框
$ `3 d/ [+ v8 aCSS代码:
. p4 ?; b" l; K! Z( Z# g#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:' k/ d9 U. b6 l. l7 b
% _) q% F% ?. M) s1 q. ~" V
+ f }$ H5 s9 ~/ n6.CSS带阴影和轮廓的边框
. S) K: Z0 ]' F3 ]3 lCSS代码:
& Z5 l- S6 v( {! n#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;
} 效果如下:/ W1 ]1 E) A& h& s% r; Y
9 P% w/ \+ D, r) I, a7 s; c
! j% }, Q* N k% C+ E! S7 Q7.CSS少量阴影和轮廓的边框. O; \8 o. L, X* O2 I2 G% _
CSS代码:
/ _, O7 e: X$ c/ ^0 q) }6 I#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 s% |. T/ f7 |: |4 }6 i5 F9 P
8 e6 E4 h7 Z& W2 _* C& N7 Q
! \% S+ y# K G! q+ i8.CSS带有阴影的双边框" R/ `0 D. U& d- F) o
CSS代码:* b! k4 l) b6 p. u3 J- S% e+ p
#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;
} 效果如下:* y- T8 H; r r3 u) [
5 ^* q" k. q- X- T" | w) h- ^9 B; `$ o
9.CSS多色边框3 m; w6 r1 T0 P. t" ]+ P# u7 Y
CSS代码:
; F# o) N9 `8 e8 P( K( `/ ~) r#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;
} 效果如下:% i/ r! \: t1 A
|