CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。: |5 D+ Z2 X$ k% e' L
以下各特效用的HTML代码相同:
. H3 f; A6 c1 ]' I1 T9 `8 H/ A<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> ' C& F) B4 K5 W- G. B& s h
1. CSS动画边框5 o$ W& S6 Q$ u
CSS代码:2 d6 O: `5 Z/ [. i8 R* J
@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;
} 效果如下:
, b/ B) e* e0 u5 g" w9 j$ ]
% |7 k$ B3 V$ N' X" b* r) D" e6 M; [& G/ z
2. CSS图像边框9 ]/ l# \) Z+ Q$ B3 G
CSS代码:3 W f: H; G6 {2 k$ V2 I
#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;
} 效果如下:% l5 p6 T5 K6 A5 W
3 C! g5 B/ g9 `( q4 M6 P7 s" @! H1 e, z1 c7 q
3.CSS蛇式边框$ g7 |. F# q7 a& m
CSS代码:
+ N* m% m$ p+ T2 J' A#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;
} 效果如下:$ ^/ b( \+ G F Z
& d8 G6 H* A0 Q4 Z
! ]6 ], [7 |) I5 L) L8 T
4.CSS阶梯样式边框+ ?' S) J; V8 K! c. O: o+ y
CSS代码:) H! ^' [7 M3 E! p1 d* M1 w
#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
} 效果如下:+ Y# N6 j9 r6 M% ~, G% Q
( a& H0 z7 Z2 w- Z
P: {4 u6 Z) d5.CSS只有阴影边框' L0 |+ _# V w/ G7 J
CSS代码:
2 u* _' J' ^& f: b: @6 a- g#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:! K# ~, K% z; K7 u6 |; o
- {3 D) s/ i) O9 [
# K3 B+ ^+ j3 k9 ]; C# z6 d6.CSS带阴影和轮廓的边框
; \! C* {& a( T' k% kCSS代码:
9 V/ ^% y% P- p& b#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;
} 效果如下:7 B Y2 }8 V" R8 E, ~
1 F. o4 J3 u& B/ S$ b! q2 |) _2 o& A! O! w- A
7.CSS少量阴影和轮廓的边框
8 a' D4 h; b9 e$ g- V7 ECSS代码:
9 v7 Q* }5 k# u( P- q#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;
} 效果如下:) q- n0 H( L. _! K- ]# d* O* G
% ]& Y5 `/ Y8 j. F% L; z0 S7 V/ e
8.CSS带有阴影的双边框
# K2 Q, u( v5 M6 A, W+ I' sCSS代码:
& [5 e! |; \! q g1 w8 b' ]#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;
} 效果如下:
" X0 `- @* O+ q. z9 W0 B: T. K
% [3 s5 @2 b" {$ B1 O5 r: N
; b# y% }8 t4 R# M4 D( N, b$ L9.CSS多色边框' _4 T$ E4 S4 R" W2 c) w
CSS代码:6 v) m( O( Z" k6 c+ Z0 g4 E a# [
#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;
} 效果如下:" X6 p! u- W7 L9 X# c" Q
|