CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
% e) [9 w) w# ]7 r* w 以下各特效用的HTML代码相同:
Z" n& e9 E% Y3 X' T, u<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
8 j9 y& _6 S. K( k" I+ R j2 {$ M1. CSS动画边框0 C& Q% L$ h4 b/ I
CSS代码:* A; N- t1 N1 Q1 }& G# e$ ?1 L: `
@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 F8 Q: L+ A: w& b
, a8 b5 k' F; D% m! N
% q) @* ?" x4 g7 {
2. CSS图像边框/ d. \( ^' T. Q/ J' x# X3 l7 n
CSS代码:. W) v1 I" S, E
#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;
} 效果如下:
% o/ ]& `+ t6 p9 P
( I0 F# ~+ e$ T `4 c; _
" N' v9 ~9 U; A" b3.CSS蛇式边框
" w- t. U0 e: a9 DCSS代码:( I" E" d' b( N, o
#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;
} 效果如下:
1 Q, E' r, {& [+ j" `& x
6 ~+ {2 j1 C- s# |% v: P7 K/ P; {! ]' k6 e" H, Y/ ^
4.CSS阶梯样式边框, y, G. R( u& I: b
CSS代码:, L7 _, d! F7 p
#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
} 效果如下:
5 {( x4 a# v! B1 P7 I
( G9 Z, ?; ]( w0 Y$ f t9 f
- l" m3 D% K9 w0 I/ ]5.CSS只有阴影边框8 j# f2 P5 y& q- z
CSS代码:
! O/ Z0 H T; P; ]' b" j#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:' U8 ]# m5 b5 k3 v% O
2 A9 i! I6 Y* o( |
- b- ?. ~: u3 i; h9 q" E: Y; B7 r/ M6.CSS带阴影和轮廓的边框7 v2 }: E$ e; n& q
CSS代码:
* ^( J2 X! \0 `4 c* Q2 |, s#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;
} 效果如下:3 J3 r8 {& ^2 i3 l7 S
- m( k p v4 L9 n4 |: F' v' d; T# E
7.CSS少量阴影和轮廓的边框
. K' b2 ]# S" @, jCSS代码:
! n; H2 M \7 r9 n$ ?4 R8 K#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;
} 效果如下:/ d$ V' y: w$ _3 x' W+ \% t9 p
3 h8 F3 ~3 e! I- c! d3 w( l( [
+ L! n! T' B+ r z
8.CSS带有阴影的双边框
$ E( `9 f9 N& `3 D3 E# n# WCSS代码:
' p" c/ X5 n7 ?& D3 j2 C4 y6 w#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;
} 效果如下:2 `" [, Q! c+ v; l$ ^2 A3 j3 n" B
% W: R; W4 f, X9 z( w' D
0 n: d' U- _- C- u! G
9.CSS多色边框
2 y1 o% s+ N$ k0 H4 V X; N1 q2 k$ qCSS代码:
. a8 o' R8 _4 B; }#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;
} 效果如下:
7 K3 B3 w% e6 ?- d3 @* G# v
|