浮动嵌套div的填充高度

发布于 2024-12-20 11:50:14 字数 2347 浏览 0 评论 0原文

我正在制作一个基本的评论系统。当评论很短时它是完美的,但是当用户写很多时,评论并不像应有的那么花哨......我尝试用 height: 100%; 填充空间,但是它没有像我预期的那样工作。我希望作者信息填写评论的高度。

到目前为止我已经尝试过: http://jsfiddle.net/anWVC/3/

HTML:

<div class='comment'>
    <div class="f-left">
        <small style="font-size: .8em;">23:44 - 10/12/2011</small>
        <img src='http://comenzarjuego.com/wp-content/uploads/2010/02/pikchu.jpg' width='96' alt='Avatar' />

        Pikachu_Monster<br/>
        ------------<br />
        Age: 19<br />
        Comments: 67<br/>
    </div>

    <div>
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla consequat mattis nibh eget viverra. Vivamus dolor erat, eleifend mollis fringilla nec, sodales in sapien. Praesent sit amet adipiscing augue. Fusce fermentum luctus euismod. Fusce ac elit enim. Maecenas tempor volutpat tempus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In vitae lectus non sapien consectetur rhoncus. Sed mi mi, sagittis ullamcorper rutrum nec, imperdiet nec libero. Sed commodo orci eleifend mi sagittis et auctor massa convallis.

Nam vitae velit vitae ante eleifend dapibus. Quisque tincidunt risus quis magna sodales non scelerisque elit malesuada. Vivamus mattis diam sed ipsum gravida nec porta odio ullamcorper. Sed at velit eget libero mollis dapibus vitae at sapien. Sed adipiscing lacinia justo ullamcorper hendrerit. Phasellus tempor sodales libero, eget ultrices tortor sollicitudin condimentum. Curabitur id nisi metus. Quisque posuere sapien laoreet est consectetur pretium sed et erat. Etiam eget enim metus. Fusce rutrum blandit porta. Etiam posuere semper accumsan. Curabitur et justo massa. Sed tellus sem, congue a consectetur vitae, tempus quis leo. Ut lacinia gravida neque ac viverra. Cras placerat ante ut justo tempor condimentum. Donec interdum, felis a dapibus hendrerit, augue ante sodales leo, vitae molestie arcu neque a magna. 
    </div>
    <br style="clear: both;">
</div>

CSS:

.f-left{
    float: left;
    text-align:center;
    background: #ccc;
    width: 128px;
    margin-right: 16px;
    height: 100%;
}
.comment{
     background: #aaa;   
}

谢谢!

I was making a basic commenting system. It's perfect when the comment is short, but when the user writes a lot, comment is not as fancy as it should be... I've tried to fill the space with height: 100%; but it doesn't work as I expected. I wanted the author info to fill in height to the comment.

What I've tried so far: http://jsfiddle.net/anWVC/3/

HTML:

<div class='comment'>
    <div class="f-left">
        <small style="font-size: .8em;">23:44 - 10/12/2011</small>
        <img src='http://comenzarjuego.com/wp-content/uploads/2010/02/pikchu.jpg' width='96' alt='Avatar' />

        Pikachu_Monster<br/>
        ------------<br />
        Age: 19<br />
        Comments: 67<br/>
    </div>

    <div>
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla consequat mattis nibh eget viverra. Vivamus dolor erat, eleifend mollis fringilla nec, sodales in sapien. Praesent sit amet adipiscing augue. Fusce fermentum luctus euismod. Fusce ac elit enim. Maecenas tempor volutpat tempus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In vitae lectus non sapien consectetur rhoncus. Sed mi mi, sagittis ullamcorper rutrum nec, imperdiet nec libero. Sed commodo orci eleifend mi sagittis et auctor massa convallis.

Nam vitae velit vitae ante eleifend dapibus. Quisque tincidunt risus quis magna sodales non scelerisque elit malesuada. Vivamus mattis diam sed ipsum gravida nec porta odio ullamcorper. Sed at velit eget libero mollis dapibus vitae at sapien. Sed adipiscing lacinia justo ullamcorper hendrerit. Phasellus tempor sodales libero, eget ultrices tortor sollicitudin condimentum. Curabitur id nisi metus. Quisque posuere sapien laoreet est consectetur pretium sed et erat. Etiam eget enim metus. Fusce rutrum blandit porta. Etiam posuere semper accumsan. Curabitur et justo massa. Sed tellus sem, congue a consectetur vitae, tempus quis leo. Ut lacinia gravida neque ac viverra. Cras placerat ante ut justo tempor condimentum. Donec interdum, felis a dapibus hendrerit, augue ante sodales leo, vitae molestie arcu neque a magna. 
    </div>
    <br style="clear: both;">
</div>

CSS:

.f-left{
    float: left;
    text-align:center;
    background: #ccc;
    width: 128px;
    margin-right: 16px;
    height: 100%;
}
.comment{
     background: #aaa;   
}

Thanks!

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

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

发布评论

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

评论(3

找回味觉 2024-12-27 11:50:14

如果您希望浮动的左侧面板一直延伸,您可以使用填充和边距实现一个不错的技巧:请参见此处:http://jsfiddle.net/anWVC/19/

这个技巧看起来像这样:

.f-left{
     float: left;
     text-align:center;
     background: #ccc;
    width: 128px;
    margin-right: 16px;
    height: 100%;
    padding-bottom:100%; 
    margin-bottom:-100%;
}

请注意,由于这个技巧将面板拉伸到容器之外,因此您需要将容器的 overflow 设置为隐藏

.comment{
     background: #aaa;   
    overflow:hidden; 
}

If you want the floated left panel to strech all the way there is a nice trick you can do with paddings and margins: see here: http://jsfiddle.net/anWVC/19/

The trick looks something like:

.f-left{
     float: left;
     text-align:center;
     background: #ccc;
    width: 128px;
    margin-right: 16px;
    height: 100%;
    padding-bottom:100%; 
    margin-bottom:-100%;
}

Note that since this trick stretches the panel beyond the container you need to set the container's overflow to hidden:

.comment{
     background: #aaa;   
    overflow:hidden; 
}
第七度阳光i 2024-12-27 11:50:14

css

.f-right{float:left; width:350px;}

html

 <div class="f-right">
    Lorem ipsum dolor sit amet,

是您正在寻找的结果吗?它将文本保留在它自己的 div 中,而左侧的用户信息保持不变。

css

.f-right{float:left; width:350px;}

html

 <div class="f-right">
    Lorem ipsum dolor sit amet,

is that the result you are looking for? it keeps the text inside it's own div and the left side user info untouched..

遮云壑 2024-12-27 11:50:14

我想这就是你的追求。

将 id 或类添加到

中,其中包含实际注释文本(lorem ipsum 文本)。

<div id="actual_comment">

然后在您的 .css 中:

#actual_comment{float:left; width: 70%} /*Must specify a width*/

它的作用是将您的 #actual_comment 浮动到您的 f-left 旁边,然后指定 div 浮动后的宽度。

然后你已经清除了所有 div 下方和结束 div 之前的浮动。

看看这个 JSFiddle。

I think its something like this your after.

Add a id or class to the <div> with the actual comment text inside (lorem ipsum text).

<div id="actual_comment">

Then in your .css:

#actual_comment{float:left; width: 70%} /*Must specify a width*/

What this does is float your #actual_comment up next to your f-left, then specify the width for the div once it is floated.

Then you already clear your floats below all the divs and before the closing div.

Check out this JSFiddle.

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