CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。6 I- C7 m2 Q5 G& p
以下各特效用的HTML代码相同:
8 r2 U; Z$ }, ^' L" y6 b& i9 E <div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>) i& v( ~0 N3 W$ H- R/ X
1. CSS动画边框
! ]( q. G! o0 ^! O0 A3 `( R' ] CSS代码:
' y% E/ O" z+ Q @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;
} 效果如下:2 j5 O' V# @9 N0 J$ }/ d1 Y# U, r
* y; C/ N* Y! |1 g5 J% a
5 c! o( J7 ~ U$ a
2. CSS图像边框 r$ @8 S( {% D! E6 G( M" H2 F" }
CSS代码:
+ {* i; T- S) i& z4 k/ 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;
} 效果如下:
& S6 E, {& y4 L. f
% z$ A, i0 o1 Q, o
7 I5 f$ J) V. C# J
3.CSS蛇式边框
# a% g9 B5 J1 E& `( O2 u C CSS代码:
- O3 ~. g& J) W7 N' ]6 m #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;
} 效果如下:+ O G' ?% w* k, ^9 j
7 U: z! b4 w6 Q ?7 _1 |3 t
. \! J1 h2 { _1 N6 H 4.CSS阶梯样式边框
8 p/ o* c; Z K* D2 x u5 W CSS代码:* U4 f/ n$ ]3 M' D0 A& Y
#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
} 效果如下:+ `* f7 v4 e: w b$ h6 t g/ W
" h: C& Z9 ?6 Q- q, ] 9 @, H+ J3 K6 ?
5.CSS只有阴影边框
1 F' A) h8 m# E8 t; x3 C% c CSS代码:
' b0 A& R/ }) r. e8 C #box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
( P7 [# N* p5 P
3 W4 [5 G/ a6 H/ O: G8 Q/ K4 Q3 Z 1 L* ]- T: K: v# T7 h
6.CSS带阴影和轮廓的边框
9 s; ^! Z: |1 Y- ? CSS代码:
) w+ E0 `* Y; e# K #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;
} 效果如下:
+ ?3 a! V6 y" S6 @9 i; L
( z. z) ?0 g5 W9 k4 E
: K" Y! `3 C" S& b3 w6 L 7.CSS少量阴影和轮廓的边框 C; u2 c7 |9 V$ U8 l$ g
CSS代码:; X7 g9 L8 V- B9 J) B; m
#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 A) r- B9 \4 b) e( f( P& n. J
5 m* G2 A( d) E; a! B
* M$ p/ l7 q1 L# I Q 8.CSS带有阴影的双边框
. t/ c4 c [0 C. A: a. O0 E F1 o CSS代码:
- u1 E( y& n% |; y, c; W$ ?: {; 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;
} 效果如下:
9 M5 F) ? m6 c7 w/ S- K) L
e+ V: d7 ?# _4 P4 c2 j2 D
1 w" l: d Q" N7 ] 9.CSS多色边框
5 a% A3 |2 D5 `* N* B9 i7 t CSS代码:( ~! L$ d! [$ r# m7 f/ D
#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;
} 效果如下:
; I5 l$ a6 y+ }% V$ Z: L- _/ o0 R