CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
* z# b5 \; M3 \* j5 | 以下各特效用的HTML代码相同:3 O* p; J, ~* Q3 d
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
1 S) v Z, w+ m; J# T" \1. CSS动画边框
( Y8 w. V6 Y- ]; p$ H0 nCSS代码:
: V6 _1 Z" I1 y, e# i& h7 k y$ T4 V@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;
} 效果如下:9 H: |2 b$ f! A3 o
/ \5 J. G2 M! x7 z4 W: F! [& J7 K; m4 I
2. CSS图像边框2 y' ]7 {2 m. u0 f2 K% {& n
CSS代码:
: U; g2 X S6 L$ F/ s$ Z#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;
} 效果如下:) {' P) k! @+ t( c o
* e* t. N/ C/ b. x
1 M" l& V& Q! f! N' s) T% n3.CSS蛇式边框
! F; u' Z0 D8 a" RCSS代码:; s# ^. _! H7 F& W7 N4 ^
#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;
} 效果如下:
. a/ l% {3 {" {# w4 Z9 N( { D
X6 E( z. s s) ?; w) n$ W
" |( G3 @8 F$ [6 e1 v4.CSS阶梯样式边框
5 V$ p+ L& m; p4 |' Y" ?4 JCSS代码:
) c" j6 [/ {5 E8 G; G- T#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
} 效果如下:
% m! a% W9 X% P9 h/ u
+ u& ^$ `& Y1 d( q4 c% |9 U5 L. V) U& k
5.CSS只有阴影边框
% p' n; v; [+ k' p9 iCSS代码:
+ _$ W6 ^0 n6 O( L$ B( E( b/ y#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
& k4 s1 e- `' G
! Z1 c" E; |; [
" W9 z) g. k8 A8 Y) r! d. I
6.CSS带阴影和轮廓的边框
8 k# o4 E. M1 Y+ {, y- \! M1 P: BCSS代码:$ x. `* J) D4 Q5 M- F: a
#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;
} 效果如下:/ u/ [. @( X5 l
. }$ X9 T9 ?0 |2 j1 z0 Y
& o( i" ]" k" H% G1 ?7.CSS少量阴影和轮廓的边框% H! A/ ` P* K- X) b; h0 u$ P
CSS代码:0 y- y% N5 w7 t- l. H" c2 s- R
#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;
} 效果如下:! r; [. B6 B5 J3 K& a8 ?: d2 ]
* M& w$ {" |) b- Z/ C; F# s2 n6 D* ?: ]
7 `& I! k6 x" p& H- p8.CSS带有阴影的双边框
4 p$ |& j, Y2 i5 tCSS代码:
4 _& R, B2 t( ~( P# R; j#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;
} 效果如下:/ s) N. \ h; u& S
( K- T) r+ B( T; R; S9 `
/ I* w- j: D8 \; Z: X9.CSS多色边框
1 O; G& l" D6 u6 sCSS代码:- n: |4 s( j5 X( b. 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;
} 效果如下:6 O! H* y8 y1 `) m; y
|