如何在不使用表格的情况下复制此 3 列布局?

发布于 2024-12-08 01:43:43 字数 421 浏览 2 评论 0原文

因无法正确弄清楚这一点而感到有点沮丧。我正在更新一个旧网站,并试图在没有表格的情况下完成这项工作。我可以使用 box flex 来做到这一点,但很多浏览器不支持它。布局是这样的

[col-1-尽可能小][ col-2-应该使用所有空间 ][col-3-尽可能小]

列不需要具有相同的高度,并且所有 3 列组合的总宽度受到父列的约束。

如果我使用浮动,我无法让中间的列展开。 col-1 和 col-2 的宽度不是固定宽度。

有没有比问题(表格)更糟糕的解决方案?

这是基于表格的解决方案的示例: http://jsfiddle.net/7dsCV/1/

Feeling a bit frustrated at not being able to properly figure this out. I'm updating an old site and am trying to make this work without tables. I can do it with box flex but its unsupported by a lot of browsers. The layout is something like this

[col-1-as-small-as-possible][ col-2-should-use-all-space
][col-3-as-small-as-possible]

Columns don't need to be the same height, and the overall width of all 3 columns combined is constrained by a parent.

If I use floats I can't get the middle column to expand. The width of the col-1 and col-2 are not fixed widths.

Any solutions that don't feel worse then the problem(tables)?

here's an example of the table based solution: http://jsfiddle.net/7dsCV/1/

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

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

发布评论

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

评论(2

红衣飘飘貌似仙 2024-12-15 01:43:43

这是一个奇怪的解决方案,但是在中间的 div 上设置 overflow:hidden 会给你我相信你想要的东西:

http://jsfiddle.net/qrBXL/

我一直想弄清楚为什么会发生这种情况,但还没有抽出时间。我最好的猜测是 overflow 仅适用于矩形容器,并且浮动在 div 内包裹使其本质上是非矩形的。

It's a strange solution, but setting overflow: hidden on the middle div will give you what I believe you want:

http://jsfiddle.net/qrBXL/

I've been meaning to figure out why this happens but haven't gotten around to it yet. My best guess is that overflow only works on rectangular containers and floats wrapping within the div make it essentially non-rectangular.

得不到的就毁灭 2024-12-15 01:43:43

当你说“尽可能小”时,我仍然假设它们有固定的宽度。页面之间的宽度不同会很糟糕。
话虽这么说,您可以查看这篇文章,了解一个非常好的布局示例,它可以解决很多问题: http://www.alistapart.com/articles/holygrail/
如果您不想完成所有这些,那么最后您就拥有了所有代码,可以复制和使用了。粘贴的。

When you say "small as possible" I still assume they have a fixed width. It would be bad to have different widths between the pages.
That being said, you can look at this article for a very good example of a layout which takes care of a lot of issues: http://www.alistapart.com/articles/holygrail/
If you don't want to go through all of it, at the end you have all the code, ready to be copied & pasted.

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