如何避免 CSS 浮动换行

发布于 2024-09-16 05:28:15 字数 128 浏览 3 评论 0原文

我有一个页面,有 2 列并排(均由 float: left 定义)。

我的问题是,当我将浏览器缩小时,右列将下降到左列下方。

我怎样才能避免这种情况?并且无论屏幕尺寸如何,仍然使它们并排。

谢谢

I have a page with 2 columns side by side (defined both by float: left).

My problem is, when I scale the browser to be smaller, the right column will be dropped below the left column.

how can I avoid this? and still to make them be side-by-side no matter the screen size.

Thank you

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

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

发布评论

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

评论(2

差↓一点笑了 2024-09-23 05:28:15

或者,如果您希望它们随浏览器调整大小,则需要以百分比定义宽度。
所以:

.div1 {
float:left;
width:49%;
background:red;
}

.div2 {
float:left;
width:49%;
background:orange;
}

有些人会在这里使用 50%,我倾向于不这样做

Alternatively if you want them to resize with the browser will need to define the width in percentages.
So:

.div1 {
float:left;
width:49%;
background:red;
}

.div2 {
float:left;
width:49%;
background:orange;
}

Some people would use 50% here, I tend not to

枯寂 2024-09-23 05:28:15

将父容器设置为固定宽度或将溢出设置为自动。例如,如果您的两列宽 200px

<div style="width: 400px; overflow: auto;">
  <div style="float: left; width: 200px;"></div>
  <div style="float: left; width: 200px;"></div>
</div>

Make the parent container a fixed width or set the overflow to auto. For example if your two columns are 200px wide

<div style="width: 400px; overflow: auto;">
  <div style="float: left; width: 200px;"></div>
  <div style="float: left; width: 200px;"></div>
</div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文