0

我已经设置了我的边距和填充,submenu-img以将工具栏图像对齐到中心,但似乎它没有 100% 对齐到中心,当我尝试恢复浏览器窗口时,工具栏对齐将失去形状。

我在 jsFiddle http://jsfiddle.net/AZdat/上做了一个演示

这是HTML源代码

<div class="submenu">
<div class="submenu-img"> 
  <a href="abc.com"><div class = "icon-home"></div></a>
  <a href="abc.com"><div class = "icon-groups"></div></a>
  <a href="abc.com"><div class = "icon-members"></div></a>
  <a href="abc.com"><div class = "icon-favorite"></div></a>
</div>
</div>

CSS

.submenu {
    background-color: #353535;
    overflow: hidden;
    position: relative;
}
.submenu-img {
    float: left;
    position: inherit;
    padding: 30px 0 30px 0;
    margin-left: 20%;
    margin-right: 20%;
}
.submenu-img .icon-home {
    background-image: url(http://imageshack.com/a/img607/9549/j3oe.png);
    background-repeat: no-repeat;
    display: block;
    position: relative;
    height: 56px;
    width: 41px;
    margin: 0 55px 0 0;
    float:left;
}
.submenu-img .icon-groups {
    background-image: url(http://imageshack.com/a/img191/1220/9sb7.png);
    background-repeat: no-repeat;
    display: block;
    position: relative;
    height: 54px;
    width: 49px;
    margin: 0 55px 0 0;
    float: left;
}
.submenu-img .icon-members {
    background-image: url(http://imageshack.com/a/img62/4964/6spa.png);
    background-repeat: no-repeat;
    display: block;
    position: relative;
    height: 54px;
    width: 64px;
    margin: 0 55px 0 0;
    float: left;
}
.submenu-img .icon-favorite {
    background-image: url(http://img838.imageshack.us/img838/7659/ojv5.png);
    background-repeat: no-repeat;
    display: block;
    position: relative;
    height: 58px;
    width: 78px;
    margin: 0 55px 0 0;
    float: left;
}
4

1 回答 1

2

1)添加text-align:center到父级(.submenu)

2)添加display:inline-block;到孩子(.submenu-img)并float:left从孩子中删除

3)删除最后一个图标的右边距

小提琴

.submenu {
    background-color: #353535;
    overflow: hidden;
    position: relative;
    text-align:center; /* add this rule*/ 
}
.submenu-img {

    position: inherit;
    padding: 30px 0 30px 0;
    margin-left: 20%;
    display:inline-block; /* add this rule */
    margin-right: 20%;
}
 .submenu-img .icon-favorite {
    background-image: url(http://img838.imageshack.us/img838/7659/ojv5.png);
    background-repeat: no-repeat;
    display: block;
    position: relative;
    height: 58px;
    width: 78px;
    margin: 0;     /* Removed margin here */
    float: left;
}
于 2013-09-09T10:06:43.387 回答