CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
' p% D- o8 F, s6 h( Q 以下各特效用的HTML代码相同:+ r& M" k0 p+ |1 _- [, {) e
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
9 p: k# s. O3 {- P3 d# o% X2 u G1. CSS动画边框
3 _$ D! V* ^& t7 g, {$ [CSS代码:$ x" \) v0 i* [( p& q% i& S8 C7 h
@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 F ^) g8 U! N* x. q
T/ N: n; u" f$ g# r& N. ]0 ] z$ J1 v0 ^/ t3 h, \' E
2. CSS图像边框
0 w: e" I* [: C* i0 _) LCSS代码:
6 m# e: y) g1 R5 f#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;
} 效果如下:7 N* ~- \7 P8 L( s1 T1 p
* `3 M) s* t `5 t# G
3 i- [# Y/ n' B8 h U3.CSS蛇式边框
6 K% p1 I- X3 r/ ^/ b( \CSS代码:
5 W' F2 I# k+ w! l. p#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;
} 效果如下:
8 R$ A& ~3 S4 a0 Q% q
8 `* F$ j. C" j+ C, G3 r* A6 u( p
2 e4 q1 c/ X0 S- j4.CSS阶梯样式边框
5 s# p9 r* _5 F: jCSS代码:& P! a% T1 ]. g
#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
} 效果如下:( E5 {3 t; M' h# S) e/ P* X
! H0 `3 a; N8 R' @. Z. y5 B" h5 l
% v- y- v8 |0 T& Y5.CSS只有阴影边框: Y7 o9 b3 x3 y' R- L2 O! S$ ?
CSS代码:
4 w" t7 D" N; w2 l8 ?/ y+ X#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:( x% m* q0 d @: A0 ^
" ~3 m4 K/ c0 x5 V# i0 `' m
8 V( ~0 r7 ~2 i& `! R6.CSS带阴影和轮廓的边框
: E: m- l( I3 S I' K; BCSS代码:
, E$ M7 ]7 _ H/ c#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;
} 效果如下:
. ]5 _8 C2 H2 e$ s- }9 T9 |% i
5 P6 `! t5 @( S
# m$ t" u; }) W& o- C( `5 ^, e7.CSS少量阴影和轮廓的边框
7 X8 |/ A/ ]0 m5 f0 xCSS代码:
7 C5 b: s0 Z% X/ O: O#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;
} 效果如下:
/ i+ n' n6 K- J- k& \( @8 D
& R' O4 {3 f* n; p
& p" W, l# |- U( _8.CSS带有阴影的双边框
7 \3 ?) { x3 O, ?+ ]) b+ \CSS代码:
* K6 ]0 Y& x2 q; Z V3 m$ X2 N#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;
} 效果如下:
+ ~( r, z+ r: ^, R
# u" G, b. `$ ~8 H% v# |
1 K; x" o: @( @9.CSS多色边框1 x0 p# N" w( Q) p, R; U
CSS代码:
+ d- x; v/ i* h) W1 v9 Q#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;
} 效果如下:' U% h9 g6 y* l" y
|