CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
+ @/ D# N* ?( a, w 以下各特效用的HTML代码相同:
; q- m1 p9 V2 A# {" d) \1 e+ U! ]<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
; t3 j x% c2 e: f7 i: r4 }1. CSS动画边框
! \2 D' |% o$ ~: x4 jCSS代码:
) F7 a$ g8 }$ x% D0 G@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;
} 效果如下:6 }5 d& ]+ y3 a3 [3 ~+ @/ P
- w! c6 i2 F. L+ L4 i; n9 _0 O# `$ B2 X1 a" d# U
2. CSS图像边框
5 m; u. i. k0 g: U7 n4 ICSS代码:) O0 i, _3 ~: X; h" W' R
#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;
} 效果如下:* {% B+ g$ W. t9 D- R
8 p ^: [4 g; f% ~( K2 V) `* \7 Q1 @1 a' Q" {$ d: \* C- h4 g
3.CSS蛇式边框
7 M# i7 S% o7 ECSS代码:
$ m1 Z+ P8 Z5 F4 R( q#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;
} 效果如下:1 {# {# s# D9 q1 i& @
: I# F8 T0 A) w9 ?. {$ X5 t4 K2 [7 c
" d/ U: u2 w2 m: V9 k# B4.CSS阶梯样式边框+ R ~2 W6 u+ l2 Z$ z8 s |
CSS代码:' z0 }& K/ n: M4 F' x$ W
#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
} 效果如下:$ W$ Y2 d: {, d& @
9 O, h/ @- n+ o c0 l
; z7 g2 p$ P3 U, B# |! {) Y5.CSS只有阴影边框( J& Y, X+ |7 F1 w& d' k/ }
CSS代码:' p, p% K! j: W8 f" }# v
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
- I7 j( |6 w/ G# e/ i
" N, {* `# Z& i _$ @' A7 N
6 |4 O" i* s% s) E
6.CSS带阴影和轮廓的边框4 p! W! _( x' D4 b+ C+ M& e. @
CSS代码:& p: z& n# d- _$ b% [
#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$ d0 x# B- k9 l, Y! ~: O
/ Z! [! z7 Y1 ]# x9 z" ]: Y% K/ o( X% a1 P
- ^- A2 P1 X4 [( h K
7.CSS少量阴影和轮廓的边框
* F1 Y2 N7 T. _; XCSS代码:% @0 H6 C w- h: ]3 v( P
#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;
} 效果如下:% k% [5 ^* T5 l, A! N
. F+ n% i) J8 I- I) b1 G( e
g+ H9 H8 H7 v6 X8 B7 x8.CSS带有阴影的双边框( T9 k; C+ j4 j' F4 |. y O
CSS代码:7 a( x. x' ~# E
#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;
} 效果如下:
4 D. c) p# \- g% \
6 y# U: g. L" G7 x G) o1 e
9 H$ u! D& y# Z5 F0 y m4 g5 D9.CSS多色边框$ [( i$ r7 t$ z+ h3 u
CSS代码: Q) q2 }5 ]0 |, c$ V f7 T* 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;
} 效果如下:) M" V$ b( F1 r
|