当上面 DIV 的高度大于 X 时,浮动 div 会下降

发布于 2024-08-31 07:57:56 字数 898 浏览 4 评论 0原文

css:

.listingContainer {
    margin:auto;
    overflow:hidden;
    padding:0 0 16px 16px;
    width:660px;
}

.listingItem {
    float:left;
    margin:0 2% 3% 3%;
    min-height:250px;
    width:44.999%;
}

html:

<div class="listingContainer">
    <div class="listingItem">
    <p>Some Content</p>
    </div>
    <div class="listingItem">
    <p>Some Content</p>
    </div>
    <div class="listingItem">
    <p>Some Content</p>
    </div>
</div>

如果任何给定的“listingItem”DIV 中的内容变得太大,则正下方的 div 将下降到下一行。

内容看起来像:

[1] [2]
[3] [4]
[5] [6]

但如果一个 div 中有 1 个额外的段落,而不是错开 div,它会被推到下一行:

[1] [2]
    [4] 
[3] [5] 
[6]

这可能按预期工作,但我该如何解决这个问题?抱歉,无法提供实时页面。

有什么想法吗?

谢谢

css:

.listingContainer {
    margin:auto;
    overflow:hidden;
    padding:0 0 16px 16px;
    width:660px;
}

.listingItem {
    float:left;
    margin:0 2% 3% 3%;
    min-height:250px;
    width:44.999%;
}

html:

<div class="listingContainer">
    <div class="listingItem">
    <p>Some Content</p>
    </div>
    <div class="listingItem">
    <p>Some Content</p>
    </div>
    <div class="listingItem">
    <p>Some Content</p>
    </div>
</div>

If the content in any given "listingItem" DIV becomes too great, the div directly below will drop to the NEXT row.

the content looks like:

[1] [2]
[3] [4]
[5] [6]

but if a div has say 1 extra paragraph in, rather than stagger the divs, it is pushed to the next row:

[1] [2]
    [4] 
[3] [5] 
[6]

this isProbably working as intended, but how can i fix this? can't provide a live page sorry.

any ideas?

thanks

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

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

发布评论

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

评论(2

情魔剑神 2024-09-07 07:57:56

如果你在每一行中添加一个带有清除两者的div,或者一个行容器div,它会起作用,但是,就像dclowd9901所说,表格内容应该在表格中,这就是它的用途!

if you add a div with clear both, or a row container div to each row it would work, however, like dclowd9901 says, tabular content should be in a table, thats what its for!

錯遇了你 2024-09-07 07:57:56

像这样的事情让我很痒:

width:44.999%

有什么特殊原因你不能只使用(喘气!)表格吗?我只是好奇,因为在大多数设计中,您的设计似乎实际上会受益于表格布局。

Things like this make me itch:

width:44.999%

Is there any particular reason you can't just use a (gasp!) table? I'm only curious because, of most designs out there, yours seems like it would actually benefit from a table layout.

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