CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。 p# g7 |: x7 [! f
以下各特效用的HTML代码相同:! ^# ?& W; s8 `4 g& r9 W) T
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
! G6 e; i; L$ J3 n+ o2 P; [. b1. CSS动画边框
* X' h8 I" {" |8 YCSS代码:, Z+ c4 U3 r# P5 g) {2 ^) {
@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;
} 效果如下:' d& N9 x9 ?4 o) {( _: v+ q
. K- u) V) C# R- { n2 O8 H9 Y9 K9 N5 R: J/ c
2. CSS图像边框
' n1 k' ?) b* K- j0 y0 @CSS代码:
) d$ l/ D9 e ?1 I }" p1 k5 T6 b8 H#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;
} 效果如下:# u) B; N/ ~! s+ h: c$ i
: N$ [0 H7 }( G/ l2 e9 _# W: s/ ?
: W0 ^7 Y$ W/ n2 y5 E, z
3.CSS蛇式边框
. m# \- e! {7 N4 @% ^0 @& A- @CSS代码:
+ \- K h1 P8 F# @#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;
} 效果如下:5 E; V& B7 x3 H6 D) e1 x& w& l
3 Q5 X, [9 `- J+ c# }8 K3 Z. d+ N/ ^0 J- V/ N, J" a
4.CSS阶梯样式边框9 l$ i: u- ]. x/ Z6 }+ Q5 D
CSS代码:
% V1 J; f" F. R3 x H4 f/ U/ 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
} 效果如下:! M6 N$ i: m1 N' ]4 ~, H& [" F b/ t
" s! D. z2 h* p' _ r& i: b7 W- E+ v1 D0 G+ j Z
5.CSS只有阴影边框2 U9 T! `5 ^6 A' D: ?' ?
CSS代码:1 k7 [4 H/ y" I) ?% S, P7 t& [
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
) g5 _$ x& P7 ]+ A" L$ ~9 L9 I! Q# F
, g; @" Z( X3 D; j7 }' z9 B
( g1 r4 |4 u9 t; L
6.CSS带阴影和轮廓的边框" C+ U5 g7 o7 a+ C, }- Q3 g' c
CSS代码:" R) Z7 A) W! g+ O$ f) d
#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;
} 效果如下:2 z$ l: B& t4 x1 @$ D' D5 W, f' M
; j5 u* F; j$ j1 k6 [' T6 I, I
& b& m2 v* g0 p2 B' F! |, Z- z6 o4 M+ _7.CSS少量阴影和轮廓的边框. j: [& \' [! \. _/ ^
CSS代码:
/ R! z- q6 B/ d$ e' C#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;
} 效果如下:
8 \3 @# {& u+ l: S* m
* j. Z; X3 |, l7 \0 a1 `8 }
a5 y7 E! l% k% p7 z) F( I1 ~, M/ g0 V8.CSS带有阴影的双边框) C% ]4 P [, Y; u; I
CSS代码: |1 y% I, G- S! G
#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;
} 效果如下:7 Q3 v7 Z1 q& w; s# @8 o
) ?' H4 S! t3 |; l2 D; Z2 A) |# W
% k9 W. U: c- B9.CSS多色边框2 d" ?1 \; m U+ ]" C1 [9 B) P
CSS代码:
) E: b/ j" l9 @8 |1 ?#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 X6 Y* m3 O; V" w
|