CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。0 {# a0 w' }# u( r% h
以下各特效用的HTML代码相同:
: ]3 L' z8 ^ g<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
# Z* h+ y# O6 H( }! G# d1. CSS动画边框
6 g" T5 X7 t1 DCSS代码:* W% ]" ]8 W' N8 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;
} 效果如下:1 E$ _' l% r4 k- Z" b% h$ Z) d
3 t. O2 C7 @2 e) D! @; \! P: R
9 h, U/ S$ ?& c2. CSS图像边框" P }- [" F3 }9 R, J/ y) [ M
CSS代码:0 h7 W* \: {! F* T# n+ p# c
#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;
} 效果如下:4 ^! ]+ r9 e2 B9 ^$ m4 A6 {
' o" e- J$ c8 A0 K8 h g9 {
6 N8 T7 s% X$ p! R' D" a9 |- ?3.CSS蛇式边框& Q& f% E9 V3 y& c
CSS代码:
" ~+ n- _ D1 L4 L#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;
} 效果如下:
0 z: O/ U }+ ^. ^+ u2 p
+ ~, T% n7 {* q
! ~- a9 i& f4 h B- H
4.CSS阶梯样式边框- C+ F1 q( M& I
CSS代码:- W# q8 t9 [9 x
#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
} 效果如下:0 O3 \% i5 h0 A/ E' L
; w% J# b5 m) @( z I
& `: m5 M# ?0 n7 \; X5.CSS只有阴影边框
: m" ]; W/ Y4 K% B0 YCSS代码:4 ? f) C! y0 T0 V
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:2 e+ _/ R$ K5 |) A
, O: I& Y" c( r* @5 D9 L$ o
% b5 r: Q( N: i0 Q3 e6.CSS带阴影和轮廓的边框) Y7 `% f3 T8 G# b! }
CSS代码:, J7 a' c: ?& f- n( 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;
} 效果如下:$ f* a0 D f$ o' R! `
3 Z; e) p* i8 M- X# I/ _1 X
) y3 b3 W Y" h, {: v
7.CSS少量阴影和轮廓的边框
. d" c# W0 g- }8 Z; o' y- bCSS代码:- L/ t4 e: R7 y" i D
#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;
} 效果如下:2 c& P+ `. \; X# V
8 Q H: j) i( o k7 g: j: _1 s5 x% d- E X4 z: n/ l
8.CSS带有阴影的双边框+ y, x" L) Z. K1 y8 [" i
CSS代码:
% B% v/ g# G, s$ x, N% ^# O#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;
} 效果如下:% ^" o6 ]# ~, J* f& E6 A
5 X I8 o: n2 V) m6 c& ]) W9 X9 }0 z) |) N
9.CSS多色边框8 C6 h6 G: x, c, f( V7 s. D
CSS代码:
- m2 C# `3 {) H/ \" G: Y# F5 W#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;
} 效果如下:0 D- W! Q) @* f E* c/ x. u
|