gpt4 book ai didi

html - 使用 CSS 将工具栏图像居中对齐

转载 作者:太空宇宙 更新时间:2023-11-04 04:23:34 25 4
gpt4 key购买 nike

我已经为 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;
}

最佳答案

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

2) 添加 display:inline-block; 到 child (.submenu-img) 还有 从 child 中移除 float:left

3) 去掉最后一个图标的右边距

FIDDLE

.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;
}

关于html - 使用 CSS 将工具栏图像居中对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18695791/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com