CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。5 q; H3 [" Q5 N
以下各特效用的HTML代码相同:, K' v! W1 J6 `5 E' {, p5 H
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div>
, `+ w8 k" ~3 j1. CSS动画边框
. ?" \4 |. U! t5 k+ A3 v: S0 SCSS代码:
, {- `# R6 {7 N@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 k* k5 [% J3 A7 ?( S
) F U3 i* g6 T$ }4 f
, {0 G) Q- m7 r+ E1 L8 X3 n2. CSS图像边框: X% @; R# G& M) S
CSS代码:
: W6 j' F. l& `+ V C#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;
} 效果如下:
$ m3 V! \; N9 e4 v
1 s/ a: S4 i" m% Q; `5 z: D9 Q2 c2 {5 x6 M" I# v
3.CSS蛇式边框
/ T9 a2 i1 o$ O6 a8 ]0 `; p+ K# ?CSS代码:; S- {9 _! L( v8 j1 v9 \. g; s
#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;
} 效果如下:; g; n, x" p4 Z. j
b# N7 S2 F# W. f6 w
; z/ m, B R5 _6 g3 F1 o4.CSS阶梯样式边框
: i6 U p- Q1 ^ f3 \0 Y+ ?( KCSS代码:. x9 {& j3 H. Z1 q- C8 k
#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
} 效果如下:
8 Z4 r* V) B3 c8 t0 L% v$ r
: F) p. e s7 g2 A) C7 M0 e
+ ~3 }( t( }. \8 {9 i+ h
5.CSS只有阴影边框6 j& \# p- |& m x+ H
CSS代码:$ E2 q6 J# V4 G' [4 E5 ]* m
#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
1 E: Y- t( v4 p. f- c
5 W0 q8 ^* c, P! d& i5 _. Z; L/ q$ k" z: G2 R* A
6.CSS带阴影和轮廓的边框
3 r7 x2 n: v* SCSS代码:
( K& J% Z+ S+ S% `9 |! t#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;
} 效果如下:% m: o& z) S/ |+ u0 g2 d4 U& A
# u4 r. A& ?" C2 m* I1 s4 }5 C( N( ~
7.CSS少量阴影和轮廓的边框 f9 |/ D3 F! C( w/ C3 @
CSS代码:9 y1 ~# _0 X, ^' [' c1 y
#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;
} 效果如下:
9 y- W5 L4 m( `$ r1 h6 m
' x5 T9 y) G# o6 u! f# e* z4 F7 K- y
8.CSS带有阴影的双边框* ]5 Y6 X5 y$ `. R2 R! f
CSS代码:' t" W# r) x% I. z* j3 _
#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;
} 效果如下:8 }: K$ v# c- i0 j
2 e, x- Q& E6 ^6 {- G, A+ N
; u! u; Z* [- T! w9.CSS多色边框. p+ ?5 J: T' f+ X. D& B1 }# @/ U0 v
CSS代码:
' ^/ V) U% V) r9 Q3 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;
} 效果如下:
" Q# D7 D2 `. W6 ?) P9 A: \
|