我希望将所有内容集中在我的代码上,但我尝试了一些事情并且它的静止图像仍在左侧,所以我知道它来自float:left
关于cizgi
样式,当我不放float:left
时,它们看起来重叠而不是分开。
cizgi
颜色必须是白色但我将其设为黑色以便更容易显示。
我的代码:
.cizgi {
min-height: 10px;
background-color: #000000;
width: 600px;
margin: 0px auto;
float: left;
}
.social {
width: 600px;
margin: 0px auto;
float: left;
}
.twitter {
background: url('http://i.imgur.com/Tdon7vV.png') no-repeat 0 -2px;
width: 43px;
height: 43px;
float: left;
}
.facebook {
background: url('http://i.imgur.com/Tdon7vV.png') no-repeat -55px -2px;
width: 43px;
height: 44px;
float: left;
}
.instagram {
background: url('http://i.imgur.com/Tdon7vV.png') no-repeat -105px 0;
width: 46px;
height: 45px;
float: left;
}
.pinter {
background: url('http://i.imgur.com/Tdon7vV.png') no-repeat -160px 0;
width: 43px;
height: 44px;
float: left;
}
.posta {
background: url('http://i.imgur.com/Tdon7vV.png') no-repeat -212px -1px;
width: 43px;
height: 43px;
float: left;
}

<div class="cizgi"></div>
<div class="social">
<div class="twitter"></div>
<div class="facebook"></div>
<div class="instagram"></div>
<div class="pinter"></div>
<div class="posta"></div>
</div>
<div class="cizgi"></div>
&#13;
答案 0 :(得分:1)
float:left
移除.social
,将width
从600px
缩减到最大width
,其中包含:220px
bg
),为其提供background color
和padding
float:left
更改为display:inline-block
margin
顶部/底部添加到.cizgi
.bg {
background: lightgray;
padding: 5px 0
}
.cizgi {
min-height: 10px;
background-color: white;
width: 600px;
margin: 5px auto;
}
.social {
width: 220px;
margin: 0 auto;
font-size: 0
}
.social > div {
display: inline-block
}
.twitter {
background: url('http://i.imgur.com/Tdon7vV.png') no-repeat 0 -2px;
width: 43px;
height: 43px;
}
.facebook {
background: url('http://i.imgur.com/Tdon7vV.png') no-repeat -55px -2px;
width: 43px;
height: 44px;
}
.instagram {
background: url('http://i.imgur.com/Tdon7vV.png') no-repeat -105px 0;
width: 46px;
height: 45px;
}
.pinter {
background: url('http://i.imgur.com/Tdon7vV.png') no-repeat -160px 0;
width: 43px;
height: 44px;
}
.posta {
background: url('http://i.imgur.com/Tdon7vV.png') no-repeat -212px -1px;
width: 43px;
height: 43px;
}
&#13;
<div class="bg">
<div class="cizgi"></div>
<div class="social">
<div class="twitter"></div>
<div class="facebook"></div>
<div class="instagram"></div>
<div class="pinter"></div>
<div class="posta"></div>
</div>
<div class="cizgi"></div>
</div>
&#13;