CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。
1 p4 v/ w, X5 f4 d. m0 z 以下各特效用的HTML代码相同:$ E/ M( I% |/ J6 J( y
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> ( q: l$ }# \8 K3 s. Y
1. CSS动画边框
+ P8 w2 a/ \$ O% ~: @* xCSS代码:" `) q# ?6 H1 k; D
@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;
} 效果如下:7 h: @1 S- |2 ?
& H8 R' Q/ {! x
! f2 {7 C7 Y. G; E% H2. CSS图像边框4 B: {: Z1 E7 W! M! u
CSS代码:
* U8 w1 ?, R0 Z0 j( ?4 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;
} 效果如下:' {* N) L( Y& @% d5 y& g
! ]% u1 i" V. I; ]4 B, }8 P
, N+ Z' v+ Z: _2 f# N3.CSS蛇式边框
+ W6 u; L4 F/ o; p# ^8 a( p: MCSS代码:# U: u. F; D" H% I7 b0 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;
} 效果如下:' V( z8 @ Y% |9 _
1 [$ {. P9 G8 a9 f/ ?
! J$ g* h: a5 h5 w5 i4.CSS阶梯样式边框& Z! P/ O; q9 y; @ K4 {& m. F6 s
CSS代码:
, l& i" V2 H: K: z; u# v7 l J% 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
} 效果如下:
$ k9 L& H6 Y9 d' Z
5 W( n2 _' W( \1 n# o; ]
5 t4 i* B& M0 Q$ \' T( i0 g5.CSS只有阴影边框4 ?0 w" Y5 V* O
CSS代码:
2 G3 i; I! b. g/ `9 B! y#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
7 O7 n: H4 t4 Q3 c3 h' W
+ e+ W! Y: M3 e; M
' Y1 K$ g: @& V6.CSS带阴影和轮廓的边框
, w9 z2 O H) ]# l( u! b$ ?: O% ECSS代码:
+ ~0 n" ~5 F# h) O! z$ `5 @1 q, \, U#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;
} 效果如下:
, F! v$ [! L' [) b- q" I i
0 N0 y$ e" E& Z5 [
! z/ O! B3 Q' u0 L/ @; ~9 R3 e7.CSS少量阴影和轮廓的边框
& d, g0 i5 u! Y. v# ^4 r, ?CSS代码:
) R. L9 X8 e" p5 O2 p B+ d#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;
} 效果如下:
$ N2 g1 e" d# ^9 P, q& |: ]% h$ d
& S: Z$ h6 T: v% t, K1 v$ |9 _: p$ b# }1 c r4 w6 m, M9 j
8.CSS带有阴影的双边框 v5 Y: T* |* P: D& l0 }, @. l" c8 Z& Y
CSS代码:
8 z! \. J# @/ K" _#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;
} 效果如下:
, v& @* ^$ C( F* h
# u9 j" l5 D, c& l; i
# M; k9 j! i1 O- ?
9.CSS多色边框* y: i* J- h* ]8 r" U
CSS代码:- t- o* w. D: S9 {- `" |4 N! I! L$ r
#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;
} 效果如下:) Y: e/ V- T) z8 i; F6 ^# A+ K
|