CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
3 }0 V/ s4 `, h; x" Q 以下各特效用的HTML代码相同:
1 L$ K3 l9 W' o<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
. ^' B6 o# N/ [1. CSS动画边框# I. ], j+ L+ g. u4 d8 y
CSS代码:4 c, n2 k& x' [3 L! X( 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;
} 效果如下:
# s% X$ G% a9 A' D# |) L
" g! h8 d- p( g, K( e( @0 R
# I/ s: X. a0 S8 B
2. CSS图像边框
' _% M6 t1 ?% e* oCSS代码:: f- i v' ]3 U# k- |( 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;
} 效果如下:! Y+ B& C3 ?4 X& V8 R
* A0 k2 ] A6 L, Q4 }$ |. x$ Q$ W$ f1 G- q
3.CSS蛇式边框
0 o1 c4 o+ M9 B3 @* _( o$ lCSS代码:
m4 Q9 s1 A1 V% {#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;
} 效果如下:
Q% K% P; t* H
" ~& n+ |/ t$ I" H" U; s0 B) h9 b1 V# k
4.CSS阶梯样式边框. M" ], A( m2 Z# o3 Y& f* R" P
CSS代码:8 h; P) v6 x9 A% X4 d' C
#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
} 效果如下:" {6 p# f/ Y7 j2 J6 ^# O% ?6 m
8 I* S7 w4 I O! D* `% b4 n9 a$ M$ H/ s# H) r% Q4 Q! _
5.CSS只有阴影边框
* e1 |, s, {" e! V8 l, tCSS代码:& f; g6 r3 w4 o- T; c
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:, X9 P [9 ?) J3 `
* y1 Y- }$ w" P$ u0 B9 ~$ A! ^( j$ `: A+ M: I
6.CSS带阴影和轮廓的边框/ s8 C; E8 t1 G$ u' M# ?3 B
CSS代码:
* ~! Z" T4 y6 w, D" ]: }+ q#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;
} 效果如下:
8 C+ x2 T! I7 B- Z2 ^/ U4 G" p! @
1 g1 K6 {- @" Q) u- m& n4 r
" [( p# ?& u+ r: _
7.CSS少量阴影和轮廓的边框
8 a W/ B2 {1 t! q0 q; S6 z/ eCSS代码:
. ?: W9 q m8 M9 M4 K# O! 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;
} 效果如下:
* [3 R+ ]* A* }% p
1 {" R$ j+ y1 a1 Z/ f* y
8 y9 q9 }" c) D5 T8.CSS带有阴影的双边框
' Z4 K; @ l' i+ Z" i: cCSS代码:
3 t1 x9 k, Z) t#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;
} 效果如下:
' q C0 |0 S5 Y5 ?
( p+ e8 j' h! d5 Y' f3 m
, _1 M7 V" @/ b9.CSS多色边框
& M% t! i; P( KCSS代码:
* f9 C H1 A9 K- d#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;
} 效果如下:
, S, G# M7 M% m: i$ f1 t$ V
|