CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。- ~1 n4 Y+ U" E! ]
以下各特效用的HTML代码相同:5 b% B6 s% `+ w5 S- n
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
* R% h# Y% ~: r" R/ \ 1. CSS动画边框
" l ]/ i$ ?: x. K CSS代码:( U z4 P5 \) L) 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;
} 效果如下:& k( u ]+ L- j* O6 m3 o H( Y" j
( j: b4 }1 s9 u6 n
, \0 ^% t+ x0 C e6 Z
2. CSS图像边框
[2 S5 p2 v, u6 U0 r CSS代码:
# V/ i! _" k* s1 |+ S5 q2 Q; u #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;
} 效果如下:
6 e9 w' K7 s: A8 p! y2 o. k. R
" I& j3 {% o8 N( |7 ?! e
4 e$ {* A+ n& L8 o- x 3.CSS蛇式边框
$ [& }% D" l4 ^, w; J4 j: m' l CSS代码:! D4 e) e- r- g% V% l( c
#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;
} 效果如下:
) }- T# e3 K) o8 @
7 H6 G5 ]( e7 z$ |0 [! K4 s
/ u. T6 D! f4 x, b# [ 4.CSS阶梯样式边框
, i! l- T* g$ k2 [9 [, N CSS代码:
T: p6 K {1 k d. A0 @ #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 W" g. P; I5 H4 z& M. P
2 t# y% }3 [3 ~% q7 C. \! N- l 0 w) }7 b) U9 W$ x" V% x( h, e
5.CSS只有阴影边框
0 }7 r+ B; Y7 ~6 o0 \3 C! { CSS代码:
% z- P5 }0 i! E" I5 Q1 U #box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:$ c3 o$ P% `, x6 D4 K6 u/ g' r
0 N! n' u; r3 b4 ^1 P - _! ]. M _1 M' F1 p F: w
6.CSS带阴影和轮廓的边框 $ w8 m" W t* L. c/ h- s# e5 n' W$ _0 z
CSS代码:
/ h1 S. u o: E$ N #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;
} 效果如下:! k% Y! s; B5 L+ r- `) F
% ]1 h2 C" Z+ W
, l) C9 o( \- V# d; Q3 \ 7.CSS少量阴影和轮廓的边框
% w2 W" T! B3 z& y2 z CSS代码:
' L1 r! ?# Q$ Y4 a7 R #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;
} 效果如下:
1 m% H; D; c0 d- n
3 x* {( f, Q- D- G
0 ?: r# h+ N; `+ F6 ~* f4 Y
8.CSS带有阴影的双边框
2 U; m8 ~2 T2 c$ u1 }: t CSS代码:
# u6 p. A2 I- }7 m* b6 h$ l1 y #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& i$ ^9 [+ [( {! W3 y
. S/ T* F8 W+ Z# ?. k
9 H/ ?" j' m- q5 L! A; i 9.CSS多色边框 " z5 ]. I, n5 f4 h" K ~
CSS代码:8 t7 y# [ c% d# t2 O4 {" {
#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;
} 效果如下:3 {1 o" f3 Z. L3 ]