另一个 CSS 重叠问题

发布于 2024-12-18 18:45:14 字数 325 浏览 5 评论 0原文

更新:这是一个 jsFiddle

我希望它看起来像这样:

我想要它看起来像什么

...但它看起来像这样:

我不希望它看起来像什么

#container 水平居中,并且必须保持如此。似乎无法正确理解这一点...

UPDATE: Here's a jsFiddle.

I want it to look like this:

What I want it to look like

... but it looks like this:

What I don't want it to look like

The #container is horizontally centered, and must stay so. Can't seem to get this right...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤独难免 2024-12-25 18:45:14

当您并排浮动盒子时,会发生这种情况,一个盒子在左边,另一个在右边,两个盒子的宽度都是宽度:50%。但内边距、边距和边框无意中增加了框的宽度,导致框宽度超过 50%,并迫使右侧框移动到前一个框下方。

尝试为框设置静态宽度(需要计算)

http://jsfiddle.net/fuYYv/

this happens when you float boxes side by side, one box to the left, the other to the right, both having width:50%. But padding, margins and border unintentionally increase the width of the boxes causing them to be more than 50% and forcing the right box to move under the previous box.

try setting static width to the boxes (will need calculation)

http://jsfiddle.net/fuYYv/

楠木可依 2024-12-25 18:45:14

布莱恩唐宁的评论给了我一个线索。

我添加了

footer #container {
    position: relative;
    top: -XXXpx;
}

完美的作品。非常感谢你们这些向导:)

这对其他人应该有用。 jsFiddle 与答案。代码如下:

header, #container, section, footer, footer img#iphone { display: block; }


header {
    background: url('images/header.jpg') repeat-x;
    height: 160px;

    border: 5px solid #aa3;
    color: #aa3;
}
    header img#logo {
        margin: 0 auto;
    }

#container {
    width: 550px;
    margin: 0 auto;

    overflow: hidden;

    border: 5px solid #33a;
    color: #33a;
}

section {
    float: left;    
    width: 310px;
    height: 200px;

    border: 5px solid #3a3;
    color: #3a3;
}

footer {
    background: url('images/footer.jpg') repeat-x;
    height: 150px;

    border: 5px solid #aa3;
    color: #aa3;
}
    footer #container {
        position: relative;
        top: -320px;
    }
    footer img#iphone {
        float: right;    
        height: 400px;
        width: 204px;

        border: 5px solid #a33;
        color: #a33;
    }

Bryan Downing in the comments gave me a clue.

I added

footer #container {
    position: relative;
    top: -XXXpx;
}

Works perfect. Big thanks to you wizards :)

This should be useful for others. jsFiddle with answer. Code below:

header, #container, section, footer, footer img#iphone { display: block; }


header {
    background: url('images/header.jpg') repeat-x;
    height: 160px;

    border: 5px solid #aa3;
    color: #aa3;
}
    header img#logo {
        margin: 0 auto;
    }

#container {
    width: 550px;
    margin: 0 auto;

    overflow: hidden;

    border: 5px solid #33a;
    color: #33a;
}

section {
    float: left;    
    width: 310px;
    height: 200px;

    border: 5px solid #3a3;
    color: #3a3;
}

footer {
    background: url('images/footer.jpg') repeat-x;
    height: 150px;

    border: 5px solid #aa3;
    color: #aa3;
}
    footer #container {
        position: relative;
        top: -320px;
    }
    footer img#iphone {
        float: right;    
        height: 400px;
        width: 204px;

        border: 5px solid #a33;
        color: #a33;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文