html - 页脚中的 3 列 - 右侧对齐错误

标签 html css

为了将页脚分成 3 列,我必须在第三列使用负边距。
我相信还有另一种方法不需要强制此列就位。

HTML:

<footer>
    <div class="fLeft">
        <p>Link</p>
        <p>Link</p>
        <p>Link</p>
        <p>Link</p>
    </div>
    <div class="fCenter">
        <p>Link</p>
        <p>Link</p>
        <p>Link</p>
        <p>Link</p>
    </div>
    <div class="fRight">
        <p>Link</p>
        <p>Link</p>
        <p>Link</p>
        <p>Link</p>
    </div>
</footer>

CSS:

footer{
    background:#2c2c2c;
    height:200px;
    border-radius: 25px 25px 0 0;
    margin:40px 20px 0 20px;
    color:#FFFFFF;
}

.fLeft{
    margin:10px 0 0 10px;
    float:left;
    width: 33.3%;
    text-align:center;
}

.fCenter{
    margin:10px 0 0 0;
    float:left;
    width: 33.3%;
    text-align:center;
}

.fRight{
    margin:-160px 10px 0 0;
    float:right;
    width: 33.3%;
    text-align:center;
}

现场演示:jsFiddle

你可以看到我得到的错误,但是 -160px 对我来说是一个修复,-80px 是对 fiddle 的修复。

最佳答案

这是因为您将右侧的列推到下一行。每列的宽度为 33.3%,但 .fLeft 的左边距和 .fRight 的右边距也为 10px,导致所有宽度加在一起超过您想要容纳所有内容的 100%。如果您删除这两个边距,您将看到列正确排列。如果您想保留这些边距,则必须更改宽度。

关于html - 页脚中的 3 列 - 右侧对齐错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12572652/

相关文章:

html - 并排div w/负相对位置

javascript - HTML 实时过滤表

css - Bootstrap 3 - 是否可以删除 col- :first-child and last:child? 的填充

html - 用 beautifulsoup 选择元素

css - 如何使用 css 网格自动创建带有名称的列

javascript - 使用 html 绑定(bind)显示 ko.observable

javascript - 如何在 Ace Editor 中显示文件内容

html - CSS 不适用于通过内部链接访问 id 标签的页面

css - DC.js 表数据显示不需要的额外行

html - 如何在odoo报告中添加一个字段?