CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
% p0 `( E2 X% j u5 d 以下各特效用的HTML代码相同:! L, i$ H. n/ \8 B& ~$ v
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
- w& m3 P# K; L- O& _1. CSS动画边框
) A6 L- y/ ?" F& \. h' \CSS代码:
& n9 N/ H+ z/ B+ J@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;
} 效果如下:4 v; C; a, s4 {# K" ^' J
0 P" I' z& c# l* j1 ~) U
2 ]5 g9 q x7 N- m$ t/ ^2. CSS图像边框
* Q6 M) v' ]) o" vCSS代码: q6 d7 G$ q" B
#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;
} 效果如下:& c' P8 Q3 P, \2 Y& x
4 F) g' E. b* o1 H: {
& a/ t3 n. A( N( B# o$ M& q3.CSS蛇式边框
9 T1 Z) v! b# F" y5 m4 o- O2 ?CSS代码:
9 p+ b G7 X3 O# |& P8 x' v' \#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;
} 效果如下:
) K+ Q9 T6 b9 Y1 S" x& _2 |
- {7 q8 D/ u3 b$ P! b |9 |% j; ?6 b0 v j' V9 U" _* m) {3 x
4.CSS阶梯样式边框
0 O6 L \3 t% RCSS代码:# j' ]& k/ e9 B! F* C, f% ]$ p* A 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
} 效果如下:
' l' b4 l- x; N% s, n! K: |1 H
U: R3 H, b f8 s- H- N8 x3 _) f# C7 f1 S$ A" K4 P: d. Z
5.CSS只有阴影边框- ?& E$ O3 \9 r4 i" w" J, `
CSS代码:
' Q6 g) h2 \( D- S#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
; p3 p% c" H, ]: m
5 f% t* X4 g. e) `0 J0 c5 {
- d, i( |' j& l
6.CSS带阴影和轮廓的边框; g* i$ q' A- R# ]( d
CSS代码:
3 {5 ?% w/ p$ i/ m0 z) r7 r#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;
} 效果如下:, x' ~6 _* l1 l1 d$ Z3 u
; J- ] V( P+ h- y' K; s$ d) n8 B8 @8 c9 x& W1 V7 W; d
7.CSS少量阴影和轮廓的边框: F* q6 [6 k0 W- y7 u
CSS代码:9 F; ~+ ~. j; B: q4 `: j
#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;
} 效果如下:7 x$ ~3 B2 E: l
: a; F [9 ^( U f+ J2 P0 Q. Q1 X8 O8 }$ b4 w
8.CSS带有阴影的双边框2 b. q* Q8 u) I+ ?' G
CSS代码:$ }$ r" S# L3 L a. w# s
#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;
} 效果如下:: z$ S% c8 r" s' s
& F& ]2 g+ P8 V) A: M% m4 X2 S' v2 x# _4 K' n$ t3 G# v/ t) h
9.CSS多色边框
+ J/ E$ U: i0 a, CCSS代码:
+ O+ S; }, H4 _: m2 k3 c#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;
} 效果如下:
! a6 ^+ y9 T# p6 H$ ~
|