CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
9 T( f* @7 J# R: | 以下各特效用的HTML代码相同:$ ]( x" r- G1 L1 ]7 m
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> # {9 A* _1 i; [
1. CSS动画边框) y2 l/ g2 |6 {& _
CSS代码:
! o7 N5 ^0 X. W* v( {. 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;
} 效果如下: j- I! p8 x9 {) P
+ ]- t' e: ]+ Y- H* ^
* n2 v# d8 j z& O. A- Y2. CSS图像边框% U( O. f: s! s: D$ h
CSS代码:
! |' w* O$ k# l5 F( `" K$ [1 N#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;
} 效果如下:
( a7 y/ e2 P% ]* m: W% D, j7 m: U
) ^7 x0 R; j% Y; R$ J
5 ]$ F: q' B7 p7 J5 ?" Q. i3.CSS蛇式边框
?' A7 L2 B( B( A5 WCSS代码:
3 v6 m _0 L- m0 b#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;
} 效果如下:) S9 ~# [* _1 B5 z) b) @' y
* ~1 E) z) g. f I. v) l, M; C0 |& H- E- H3 w
4.CSS阶梯样式边框, I e7 N' a5 z5 C
CSS代码:
9 G5 Z5 y8 Q5 G+ k, N#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
} 效果如下:
1 Z7 V! G0 o/ `! `, M" b% y
3 ~0 A6 G2 r, Q5 p2 J
# s5 f$ Z/ ^+ ~" v, F0 ^
5.CSS只有阴影边框& C8 f: I( Q: W0 V1 l
CSS代码:5 Z% G9 d3 D6 k5 P9 l# b: K
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
( Q* a, z/ ^$ u0 K+ F
/ ]# o( L% N! w, O& Z S7 X( m( i, a6 \0 B1 I3 ]) Q. X# q6 y8 G
6.CSS带阴影和轮廓的边框% s+ X+ F% X+ k L' `5 r! s
CSS代码:
4 J7 }$ C1 c: B. n% 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;
} 效果如下:# G( T6 N }; L
. s) ^4 G5 i& V
5 ?3 U1 O6 q6 q! q7 k0 V7.CSS少量阴影和轮廓的边框" ?( l. p+ {4 D; k
CSS代码:+ Y& h1 @* {3 _6 P5 \+ v
#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;
} 效果如下:
# j/ N+ q5 k5 w' [$ ]
3 t" n, l" M5 E- a. \0 C- d
8 y V2 a, X9 H l8.CSS带有阴影的双边框% [- M7 D, A& B5 S' c) l6 X: w5 E
CSS代码:
7 V/ ^. z$ T5 @- B* p#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;
} 效果如下:
: v3 P" ^$ z7 P
- Y% \: F) p) N# ^4 \( q9 k( Y
! Q% F' R! _+ v" s' f# v9.CSS多色边框* l6 |4 T9 l$ g$ S5 q: F7 K
CSS代码:
! x6 m# L: [: a1 G, l7 A5 }& k#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;
} 效果如下:
- n! e6 k# d& r9 ~* b
|