CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。; c" e" V0 Z5 R3 [+ l* c
以下各特效用的HTML代码相同:2 P$ L: R- b5 R5 d O
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
8 @0 L! v% h8 U( a1. CSS动画边框
* q! o0 x. z0 e, u; {: E8 e" @1 ZCSS代码:
$ w2 ]! q. v( Q' q( |4 N@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;
} 效果如下:
7 J H) `7 h- n
( s, _8 k8 p) @2 G* S5 b! v
6 F, V3 @4 y, K$ U$ N% G2 A6 N2. CSS图像边框
: r; F N+ D7 i* [0 ^CSS代码:8 x4 v% y( K7 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;
} 效果如下:% B+ V- L! U; n0 y) Y+ M) J3 i0 y
$ Q& y' Q, M* \& |
+ S# s0 {, O$ L$ e& i. d M1 P9 j
3.CSS蛇式边框
+ S, r5 B: O6 NCSS代码:
$ r2 i4 y- \: Z#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;
} 效果如下:
8 J2 E+ M l9 u8 y
- i/ k& p. E* X9 X
, x" B& j* V! x; l1 b
4.CSS阶梯样式边框: c. f- q7 k" \: B$ h0 ?) j
CSS代码: ]; j2 L: D1 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
} 效果如下:
) ?7 P; c9 X8 a$ U* G1 ~
" Q$ e0 b! i8 }0 I9 h }
2 _( @+ @4 W# n. X5.CSS只有阴影边框. v: ]& R+ o% R* V. y
CSS代码:
, p$ G t% } g1 y' K8 d! S% W#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
7 Y+ W' H/ {2 O/ p' [( R
/ e) O1 O. B2 B% n O3 U. Q0 D- f8 \
' B7 P# l7 U$ d! Y7 F6.CSS带阴影和轮廓的边框) X/ ]$ Y3 Z6 n5 D
CSS代码:2 J' N2 F* Q& e& q K+ Z9 @# T
#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;
} 效果如下:
- h; Y' y% r& y3 I3 K7 ] y" j) v
5 ^* Z4 R! H+ E: F2 s$ q1 W1 i. I- m
& g5 V6 T5 Z4 ^. c. f% v5 p. D+ S4 @
7.CSS少量阴影和轮廓的边框! o- X7 H# x1 P3 U
CSS代码:
6 T8 h4 {& {/ K* n( I. I: X#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;
} 效果如下:
, Y) ?0 G% l% C V) B! _
) P1 b; h) J; w% c' L1 H7 d" J. y1 s4 i$ V) X( x" `. u6 H) N
8.CSS带有阴影的双边框
/ w! _6 e- l3 c& i& J) |CSS代码:$ q7 y- C7 m) Z6 G. m/ c0 i
#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- I7 i8 h k: w4 ^
F7 m4 z8 L$ T. [5 `- p& n
1 Y& G& K" E8 Z& R) u9.CSS多色边框" ]. T$ J7 x1 M9 ~* c
CSS代码:
7 w: m3 k3 `: ]5 D5 b+ 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;
} 效果如下:2 j8 \5 B; ^7 y+ V
|