我有一个页脚,我想在其中的右侧放置一个图标。图标的宽度和高度均为 36 像素。它位于一个内边距为 7 像素的 div
容器内。
根据我的计算,图标应该垂直居中,但事实并非如此。
我希望图标在顶部、底部和右侧具有相同的填充。
我究竟做错了什么?
HTML:
<div data-role="header" class="pageheader"></div>
<div data-role="footer" class="pagefooter">
<div class="info-icon">
<a class="info-anchor" href="#" style="text-decoration: none; text-shadow: none; color: #ffffff;">
<img class="info-img" src="https://storage.googleapis.com/material-icons/external-assets/v1/icons/svg/ic_info_outline_black_36px.svg">
</a>
</div>
</div>
CSS:
.info-icon {
z-index: 200;
position: absolute;
padding: 7px;
margin: 0;
display: inline-block;
right: 0;
bottom: 0;
background-color: #00ff00;
}
.info-anchor {
background-color: #0000ff;
padding: 0;
}
.info-img {
background-color: #ffffff;
margin: 0;
}
[data-role="header"], [data-role="footer"] {
height: 50px !important;
background-color: #ff0000 !important;
width: 100% !important;
border: 0 !important;
text-align: center !important;
text-shadow: none !important;
color: #ffffff !important;
}
[data-role="footer"] {
bottom: 0;
position: absolute;
}
最佳答案
只需将 display:block
添加到您的 .info-img
否则它会获得额外的底部间距(默认情况下图像是 inline
元素)。您可能还想将它添加到 .info-anchor
以覆盖整个图像
关于html - 页脚中的图标定位不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32096312/