CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。- F2 m q0 t+ o# Q4 M
以下各特效用的HTML代码相同:
! d; Y8 |; I) c6 q: U<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> / a S: z1 f. y) r
1. CSS动画边框% l/ K2 l8 ` E( a( F8 l
CSS代码:& d }4 [3 g8 \% E n" U5 O
@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;
} 效果如下:5 D) Z3 Y; |8 }( P" }) }
" ]: q3 m# n9 z+ P$ d$ L" ]1 M
6 W. t+ c8 u5 c$ @* n, }6 t2. CSS图像边框- C6 J' n: u* m4 E- t7 n
CSS代码:" I- n; H; X! h' ]% x" X+ [* Y9 ]
#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;
} 效果如下:
3 Y$ k) G& F0 j$ i6 ?# K' y+ s- O. `
" g, B8 s! {# H2 j' L U
8 F1 x% [ d# c5 i& D @' K
3.CSS蛇式边框
, i' R) f; e. X$ T ]CSS代码:5 Y3 U# a6 w8 h
#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;
} 效果如下:
& d4 d: u; [) s l- ]
z. s; m: R% f
. l! Q( t: W, {# @4 @. q2 T9 x' I9 J4.CSS阶梯样式边框
5 {' n8 G& p! Q2 ]. \( N3 ?CSS代码:
8 k+ x, s, }* S2 b9 V o#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
} 效果如下:
# G( u# s+ A. @) R
+ M0 r1 }, p) Q& {, w, P& g
1 P! n( C# R; |6 V
5.CSS只有阴影边框 u* I6 ?- Z4 h
CSS代码:# ~; d! I6 L2 p2 j2 E& }
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
9 S4 L) u, Y5 A
# K: v: i4 n+ o. c0 J! l
3 p/ y8 {" |! ^$ w3 T$ v6.CSS带阴影和轮廓的边框) x! d L m- r' I4 G1 o8 D n- ^9 k* i
CSS代码:
2 m" t, p/ K& j+ y# E. s4 ~#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;
} 效果如下:
3 I/ k( {3 ^. D5 ^2 _8 f" ]$ _* c
4 Z l3 g Z: P) X& D+ p4 y$ U
# I2 L7 n; O# s$ c/ q; T
7.CSS少量阴影和轮廓的边框
& g6 I: E- l, z1 q0 vCSS代码:
; p0 g4 ?3 K8 K" l2 t4 V5 W#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;
} 效果如下:
4 A; }8 @4 I: \* [' E# L# O2 F9 ~
8 ]3 \8 A' d0 d0 g. \+ S! }5 c
! i2 X4 p4 \ D8.CSS带有阴影的双边框
3 N) Z0 g4 S, @) tCSS代码:4 P$ m( R6 k" ]0 c
#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;
} 效果如下:
! b; n) n; p! U& j
' r' o& K) P/ `- @( s" O. v% Y- J$ E* k$ \
9.CSS多色边框
1 ^3 s. Z. N, O# T8 s4 CCSS代码:' Y* {/ T/ N2 {% U: G
#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;
} 效果如下:( v$ v( s7 F6 ?% d p- Y
|