div 高度随着位置变小:相对比绝对

发布于 2024-10-18 08:52:36 字数 1978 浏览 4 评论 0原文

嗨,Stackoverflow 用户...

我有一个网站,我正在尝试将其设计得非常酷。

http://kebax.dk/blog

如你所见,我的问题是“border”不覆盖最后两个 div。

这是 Div 的结构:

<div id="blog">
    <div id="bloghead">
        #Blog headline
    </div>
    <div id="blogbody">
        <p>Test tekst!!</p>
        <p>Test tekst!!</p>
        <p>Test tekst!!</p>
        <p>Test tekst!!</p>
        <p>Test tekst!!</p>
        <p>Test tekst!!</p>
    </div>
    <div id="blogcreditsleft">
        Written by: Kristian
    </div>
    <div id="blogcreditsright"><?php echo date("Y-m-d") ?></div>
</div>

这是它背后的 CSS(您也可以查看我的样式表):

    #blog {
        .rounded();
        left:65px;
        position:relative;
        width:520px;
        margin-left:auto;
        margin-right:auto;
        padding:5px;
        background:#052507;
    }

    #bloghead {
        color:#000000;
        background:#2BAC2B;
        padding:5px;
        border-bottom:1px solid #052507;
        font-size:14pt;
    }
    #blogbody {
        color:#000000;
        background:#42E64F;
        padding:5px;
        height:auto;
        overflow:auto;
        min-height:300px;
    }
    #blogcreditsleft, #blogcreditsright {
        color:#000000;
        padding:5px;
        width:250px;
        .gradientVBottomCenter();
    }
    #blogcreditsleft {
        float:left;
    }
    #blogcreditsright {
        float:right;
        text-align:right;
    }

我可以使其工作的唯一方法是通过设置position:absolute 并添加 left:65px 将其推入我的“中心”的中心:) 但我的问题是,当添加更多博客元素时,由于绝对位置,它们不会仅仅位于彼此之下。

我怀疑这是因为缺少clear:both,但我不知道如何修复它......

任何人都可以帮忙吗?

编辑: border...

Hi Stackoverflow users...

I have this website I'm trying to style really cool.

http://kebax.dk/blog

As you see my problem is that the last part of the "border" does not cover the last two div's.

Here's the structure of the Div's:

<div id="blog">
    <div id="bloghead">
        #Blog headline
    </div>
    <div id="blogbody">
        <p>Test tekst!!</p>
        <p>Test tekst!!</p>
        <p>Test tekst!!</p>
        <p>Test tekst!!</p>
        <p>Test tekst!!</p>
        <p>Test tekst!!</p>
    </div>
    <div id="blogcreditsleft">
        Written by: Kristian
    </div>
    <div id="blogcreditsright"><?php echo date("Y-m-d") ?></div>
</div>

And here's the CSS behind it (you can also just check out my stylesheet too):

    #blog {
        .rounded();
        left:65px;
        position:relative;
        width:520px;
        margin-left:auto;
        margin-right:auto;
        padding:5px;
        background:#052507;
    }

    #bloghead {
        color:#000000;
        background:#2BAC2B;
        padding:5px;
        border-bottom:1px solid #052507;
        font-size:14pt;
    }
    #blogbody {
        color:#000000;
        background:#42E64F;
        padding:5px;
        height:auto;
        overflow:auto;
        min-height:300px;
    }
    #blogcreditsleft, #blogcreditsright {
        color:#000000;
        padding:5px;
        width:250px;
        .gradientVBottomCenter();
    }
    #blogcreditsleft {
        float:left;
    }
    #blogcreditsright {
        float:right;
        text-align:right;
    }

Only way I can make it work is by setting the position:absolute and adding left:65px to push it into center of my "center" :)
But then my problem is that when more blog elements are added they won't just be under each other, because of the absolute position.

I suspect it's something about a missing clear:both, but I have no idea how to fix it though...

Can anyone help?

Edit: border...

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

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

发布评论

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

评论(2

南…巷孤猫 2024-10-25 08:52:36

我不得不盯着你的网站几乎整整一分钟才能理解你在说什么,我怀疑其他人也在做同样的事情。该边界非常微妙(很容易错过)。

解决此问题的最简单方法是将 overflow:hidden 添加到 #blog"清除浮动"

(或者overflow: auto,但过去的经验告诉我更多的赞成票会投给hidden

I had to stare at your site for almost a full minute to understand what you were talking about, and I suspect others are doing the same. That border is quite subtle (easy to miss).

The easiest way to fix it is to add overflow: hidden to #blog to "clear the float".

(Or overflow: auto, but past experience has taught me more upvotes go to hidden)

零崎曲识 2024-10-25 08:52:36

您的浮动元素正在逃离容器 div。

在“blogcreditsright”之后的标记中再添加一个块级元素。

<div class='clear'></div>

CSS

.clear{
    clear:both;
}

Your floating elements are escaping the container div.

Add one more block level element to the markup after the "blogcreditsright".

<div class='clear'></div>

css

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