html - 页脚中的图标定位不正确

标签 html css jquery-mobile

我有一个页脚,我想在其中的右侧放置一个图标。图标的宽度和高度均为 36 像素。它位于一个内边距为 7 像素的 div 容器内。

根据我的计算,图标应该垂直居中,但事实并非如此。

我希望图标在顶部、底部和右侧具有相同的填充。
我究竟做错了什么?

jsfiddle

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 以覆盖整个图像

Updated fiddle

关于html - 页脚中的图标定位不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32096312/

相关文章:

javascript - 使用 background-size :contain 时获取 div 背景图像的 XY 坐标和高度/宽度

html - 将搜索框居中对齐

javascript - 检查元素是否有CSS动画

java - 我可以使用 WebDriver 获取元素的 CSS 属性 "padding"吗?

android - 无法从数据库加载图像;只显示网址

javascript - 无法以编程方式关闭 jQuery Mobile 弹出窗口中的可折叠项

javascript - 如何在表行中实现类似 Spotify 播放按钮的按钮 css

html - 像 aria-label 这样的 ARIA 属性应该可以在 HTML5 中翻译吗?

具有不规则边框的 CSS 文本突出显示

javascript - 防止 iScroll 滚动 ListView 过滤器