html - HTML/CSS 中的填充和链接问题

标签 html css image hyperlink padding

我是 HTML 和 CSS 的新手。我有一排链接到各自页面的社交媒体图标。的 HTML:

<div id="social">
        <a target="_blank" href="https://www.facebook.com/">
            <img title="Facebook" alt="Facebook" src="img/social/facebook.png" />
        </a>

        <a target="_blank" href="https://twitter.com/">
            <img title="Twitter" alt="Twitter" src="img/social/twitter.png" />
        </a>

        <a target="_blank" href="https://instagram.com/">
            <img title="Instagram" alt="Instagram" src="img/social/instagram.png" />
        </a>
    </div>

这是相关的 CSS:

#social {
    text-align: center;
}

#social img {
    width: 6%;
    height: 6%;
    padding-right: 20px;
}

问题是右填充的 20px 是链接的一部分,这是草率的。如何在不链接该空间的情况下在图标之间创建空间?干杯。

最佳答案

只需在 a 元素上设置边距(最后一个元素除外,其中边距既多余又可能影响布局):

#social {
    text-align: center;
}

#social img {
    width: 6%;
    height: 6%;
}
#social a:not(:last-of-type){
    margin-right:20px;
}

关于html - HTML/CSS 中的填充和链接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30400309/

相关文章:

html - Bootstrap 3 中的垂直居中导航项

javascript - onClick 函数不适用于 anchor 标记

javascript - 当点击 1 然后谷歌地图不显示

python - 将图像转换为 numpy 数组,然后立即将其转换回图像会产生两种不同的结果

c# - 外部窗口上的图像叠加

jquery - Materialize css select 不使用 jquery 步骤

jquery - onmouseover 显示 div 调整 x 和 y

javascript - Bootstrap - 404 找不到文件

css - App Engine Imagine API 上的调整大小 API 如何工作?

javascript - 在 "swf"""中播放/显示 "a rel="