CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
! D0 l8 F x1 m; [! X 以下各特效用的HTML代码相同:
7 X! A$ ?6 \1 Z9 U<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> & j* ~% `0 s0 J8 G
1. CSS动画边框
, w" n; T8 [7 P, s! ?4 v! a( a; X9 YCSS代码:
% |' k5 e6 ]) ?, ]5 F- b' {2 K& v@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;
} 效果如下:
( Y; M. \9 Y# i- |/ u2 ~- x
( P! q# P/ j2 I) Z" Y7 d+ g( {. J5 x
+ Q# v; b% S. ~. m& s2. CSS图像边框
8 a4 N# x5 f8 Q, jCSS代码:' [. ^& Q" U5 S. B: `; R- w
#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;
} 效果如下:8 }" v4 c1 g' u% `5 J
! V9 l# L2 l* d' P
. F/ A# d! J: n% S( z8 k3.CSS蛇式边框; B, e: H0 K, @6 T+ z3 D$ q! C' u
CSS代码:
" E* Q- F0 J% F- V2 m#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;
} 效果如下:+ i1 a' V& w' ^, V: R
7 o9 ^1 d! @ O8 i0 ~+ H* c
' b! l2 r; G! |% A5 Y. C4.CSS阶梯样式边框# N A9 N+ o3 J5 L- W, p# W6 Q
CSS代码:
$ E% [% o1 s/ r" }0 u5 Y/ j G! T#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
} 效果如下:
" F' K; F1 n) N; x# s+ [3 I
% {* o& b# A/ O c( B* S
: c& U D; \# i4 w5.CSS只有阴影边框' K6 j5 {6 f$ A5 H/ F9 }2 V t- ]
CSS代码: T' x5 x) _" O; u' h
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:% b; o5 u' y# V2 P
# N/ ^/ a: ]2 c4 a: h" h
# }, j" a8 h3 A& y; K& t+ v
6.CSS带阴影和轮廓的边框
7 ^4 n' }5 m6 |' M. |) S; A4 BCSS代码:, W4 a, g* g' W" D0 E* K, z5 j
#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;
} 效果如下:
: r5 V/ Y. k! V" p1 u, ^5 p/ }
2 Z" X8 q& M. r" |* i
: A* ~3 z( E4 e/ m( z3 L1 {9 f
7.CSS少量阴影和轮廓的边框
( o& @9 c/ {* A1 H4 s) q2 RCSS代码:
1 t. }1 g1 {0 }5 Q C4 j% ]+ R! a#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;
} 效果如下:
- f' y' n) H8 B+ D$ B% O) c
' m# n4 \ K" i; z. E$ f% }& z; O. c1 a0 ]4 p
8.CSS带有阴影的双边框
0 ]# r) p/ [& vCSS代码:8 r5 ?8 H: [. Z5 x5 ]9 d
#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;
} 效果如下:; S( J$ N- N J/ T' O# ~; Q" z# E
1 o5 j5 g% E3 q& _8 R. j' E: X
2 O- L2 x& G+ X4 ]" N @
9.CSS多色边框 }0 t- c+ q' ~/ r
CSS代码:5 {/ Q- i" {# [% {" f1 S
#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;
} 效果如下:% @; z' I( H N1 e& c
|