CSS 样式是边框最重要的一个方面,这不是因为样式控制着边框的显示(当然,样式确实控制着边框的显示),而是因为如果没有样式,将根本没有边框。3 t/ w% R/ A- D3 @( t5 [6 F
以下各特效用的HTML代码相同:+ R `3 V7 t0 E
<div id="box">
编程适合那些有不同想法的人... <br/>
对于那些想要创造大事物并愿意改变世界的人们。
</div> 0 D% W. Z U) s6 A$ l# ^
1. CSS动画边框; d! {& E- y! s' u
CSS代码:
# t' `1 E9 O* j6 K1 C7 A@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;
} 效果如下:
% o$ R8 J8 l, X4 U8 C
8 P% E4 q+ F: T" G# |
% A. g& [% m9 ]2 y7 e
2. CSS图像边框$ c0 n* Q- ?8 w7 L7 f# A
CSS代码:* F1 l. G- b% l/ X9 d+ R
#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;
} 效果如下:1 @* Y. N- N7 s/ z' b
/ V, t& @" H( Y) A# ?0 o5 k
4 s# a8 j2 h9 `7 t% }1 I3.CSS蛇式边框
0 ?8 R2 U u2 yCSS代码:
: I2 [8 z* K3 A+ @ h#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;
} 效果如下:! k6 e5 _8 [6 h; ^) |
2 {; _# J0 ]. v4 N1 r
/ H+ T9 r8 e k& S' R+ K
4.CSS阶梯样式边框% ~* t6 K [+ h" m
CSS代码:
3 m. i0 _9 \( ?#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
} 效果如下:# v3 I! v3 |$ [' B
* V- S$ U, p; U
6 \: c5 D0 @) O- f5 J, {" v9 e: i" g: J. M4 |
5.CSS只有阴影边框) l4 ^- N+ `3 `
CSS代码:
' D a9 ^- w3 M; U#box {
font-family: Arial;
font-size: 18px;
line-height: 30px;
font-weight: bold;
color: white;
padding: 40px;
border-radius: 10px;
box-shadow: 00010px white;
} 效果如下:
, ?" n7 Q1 Q) N
. _7 |4 _# o o# ~ |' M) U6 \2 E2 {9 [& F! L/ b
6.CSS带阴影和轮廓的边框
$ b G. m% T8 DCSS代码:
( `9 U+ M" C# L0 H9 e4 X: w& Z1 |#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;
} 效果如下:
& `$ E k) c" S) ^% N2 {
$ S' ^: |% [/ `" T9 y3 R3 @! d5 p* E. s9 n
7.CSS少量阴影和轮廓的边框
' w: Z4 {* H5 S# T" SCSS代码:
1 I& n* v; H7 s- s; k2 n5 `#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;
} 效果如下:( [ H9 O/ g+ I1 t/ Y
& |1 h9 F" U: R2 N! A
7 x8 j. c- E8 o
8.CSS带有阴影的双边框
3 i, v) F& \0 L/ O+ JCSS代码:
4 s: F2 g4 g7 p2 A, L: ]#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;
} 效果如下:
% h" P/ M8 K- F: o F! _
& |# h" ]1 M8 Z4 k9 p% f
/ _9 I6 k( I# w1 ?. Y
9.CSS多色边框
1 U( R! m, I. p, v6 z' ]* A$ cCSS代码:
9 V# n4 c' V$ K3 d) m, ?9 H# y$ V#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;
} 效果如下:
2 {* V) t( |9 C$ W5 b# N
|