CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
. M% B% Z9 D5 b0 o0 r 以下各特效用的HTML代码相同: p. {( z" Q+ H+ {
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
2 [$ s& g" w/ M& o6 Y6 T1. CSS动画边框
% s* V/ M9 Y- T+ x2 YCSS代码:
; t7 v) l% Z0 q3 \2 n v2 z@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;
} 效果如下:6 C/ K/ R' Y; w. l
+ b) b( @, Z4 ~; n" w0 b6 g' D% B$ w
2. CSS图像边框
* a$ P$ n" f; |! J8 h4 F1 `: y! OCSS代码:4 D8 M* {3 y2 k
#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;
} 效果如下:
. r, r) o* a: R$ o
$ _6 |. X \6 D. I* h, A2 S8 T
0 G$ f8 @) \/ M$ r
3.CSS蛇式边框6 H2 x9 e' G4 S4 X
CSS代码:1 d1 W2 s. s/ L* A( w5 m
#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;
} 效果如下:
6 n3 P% s( s" w, p! a; {
; _8 d- O2 L u% U% C. g0 f
# v8 j b& ?2 D! y
4.CSS阶梯样式边框3 @$ y: c2 U6 x; G
CSS代码:
6 j# J! o$ C5 u#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
} 效果如下:6 z4 }- f( K% k2 S; R) X
; e8 @7 H0 W$ n, C5 I
+ N9 G- m% T J$ f+ ?' X# h9 Z& b5.CSS只有阴影边框
! Y7 {9 C2 |8 x' v4 eCSS代码:
/ A- W' t+ h7 Y9 I#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:" c% h& ~9 R+ P' G) p N
/ p9 H4 g0 [$ Z5 ? i2 Z2 _3 j5 j; f$ W; s. A1 e
6.CSS带阴影和轮廓的边框
/ c/ h Q" x4 \8 z: WCSS代码:0 t7 O6 C$ ` r( k% I) y
#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;
} 效果如下:
5 O! q b" t+ S5 O1 \8 a6 N
6 _- K$ T W4 C& j
' b6 Y- u, k9 a5 c) W+ T: g7.CSS少量阴影和轮廓的边框6 A$ i; R5 z5 a0 X6 I
CSS代码:3 [! [) o0 H/ ?0 i- G0 O# N
#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;
} 效果如下:
( Y5 @& G6 R% K
- U! V# s/ W# b, S! m7 ]
$ U% d4 ^0 \9 Y# H$ e9 Z8.CSS带有阴影的双边框
8 z$ T" Z7 b8 q# s% V7 DCSS代码:% P6 y+ V) H+ ?
#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/ w& Y5 g8 F' |( P! p, U
/ M$ U. m: R1 F# D; C8 N6 {7 Z: v8 q% _% j2 k
9.CSS多色边框% b. [0 Y1 t! H m' b% ~
CSS代码:0 i. i3 E) T2 L6 k, R/ s+ n
#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;
} 效果如下:
( V! q* d5 g3 x$ d* p R- E; u7 V w$ [
|