CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。3 g! w% U, p/ x9 x( v3 v' U
以下各特效用的HTML代码相同:
+ Z4 z+ o9 J+ |! G/ l8 h' @( B( {<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
1 x4 K/ \ j, ~% {# J1 H1. CSS动画边框, b! I. q' D5 @
CSS代码:
) y" W) d: F; @/ \ k$ v! e* t@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;
} 效果如下:
$ o* J( y: T# B) n/ D- \5 G9 v
' b5 }, x1 |* f6 R9 v* e5 U3 @. y* m: o! a1 _
2. CSS图像边框$ n1 {5 g0 b9 Z/ S8 Z. Z4 C3 d% H/ h
CSS代码:
/ B2 y' D2 |8 m; L#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;
} 效果如下:
k# H- P# M# R5 K" k2 u
; h" _: B0 l- V: u0 o) k. S/ a( c
1 C9 _7 C+ c* \- Y& ?; H3.CSS蛇式边框
3 h1 g* b4 G; MCSS代码:5 d: `% z# B9 l- n9 y2 m5 t; e
#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;
} 效果如下:
; [; r+ T; X# @2 f& ?
( H( x" a1 l. x# J- E M+ v6 R
! C* E$ k& s$ b J! Q6 r4.CSS阶梯样式边框
" x4 f) ]! d R, ~2 lCSS代码:
8 G1 r6 T5 M O. {, m8 B 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
} 效果如下:: h, r9 Z* s. i' V
/ \+ }+ J+ Z k0 p
; H* M2 j& m+ n
5.CSS只有阴影边框
- f7 P8 J) M+ V3 p4 P0 F3 pCSS代码:
9 |$ T) k. R& ?$ q! W( R#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下: C+ H2 w* ^; y( W
3 C% U; S' A' p. f. E* t1 h
6 N# ?) Q! n/ u$ H# t! r H w9 d6.CSS带阴影和轮廓的边框
) h$ M# a i4 w0 cCSS代码:/ [" \$ E D9 m* m: w
#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;
} 效果如下:+ r+ i+ F0 Q) L( L+ _
0 m7 F: O8 c* @0 q5 T4 {7 ~. y9 t
; E {: N: q0 {9 f7.CSS少量阴影和轮廓的边框
* _5 [! T. a# o+ r! F+ ?CSS代码:
/ d8 u6 b) e# p5 B#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;
} 效果如下:
: S, F0 |9 _& `4 Y
# I+ T1 t; |1 d: s' U) x1 O' O2 I; ^- C' ^
8.CSS带有阴影的双边框% I+ E% @& a, A
CSS代码:
- ?1 V' _7 G- l+ E4 |2 y q#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;
} 效果如下:
, @5 j2 ], i- E0 L7 k
! t% N# L6 r& {" {- T, P6 |/ Z1 c
" [& N j. \1 z4 y9.CSS多色边框" ~/ V$ D/ {+ p6 S- a
CSS代码:4 v4 X' C" B* L
#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;
} 效果如下:
7 W, W" t1 E! Z) G# z
|