自动宽度、百分比和固定宽度导致 DIV 换行

发布于 2024-12-04 02:45:18 字数 1721 浏览 1 评论 0原文

我想要一个三列页面,其中中间的一个具有动态宽度(窗口调整大小)和一个最小宽度(div #middle: min-width:400px;< /代码>)。

问题是当我调整大小时第三列正在换行。

我知道如果我用 width:500px; 替换 #middle div width:75%; 这会起作用并且右列不会换行,但我不会不再有动态宽度的中间列...

我如何解决这个问题?

#contentwraper {
  position: relative;
  min-width: 800px;
}

#left {
  position: relative;
  float: left;
  background-image: url("http://www.artetics.com/images/artfrontpageslideshow.png");
  background-repeat: no-repeat;
  background-position: center center;
  min-width: 128px;
  width: 12%;
  height: 128px;
}

#middle {
  position: relative;
  float: left;
  min-width: 400px;
  width: 75%;
  text-align: center;
}

#right {
  position: relative;
  float: left;
  background-image: url("http://www.emoticonswallpapers.com/avatar/art/Test-Card.jpg");
  background-repeat: no-repeat;
  background-position: center center;
  min-width: 128px;
  width: 12%;
  height: 128px;
}

.imagemiddle {
  position: relative;
  float: left;
  background-image: url("http://www.tradewindscientific.com/images/t_logo.gif");
  background-repeat: no-repeat;
  background-position: center center;
  width: 25%;
  height: 128px;
}
<div id="contentwraper">
  <div id="left"></div>
  <div id="middle">
    <div class="imagemiddle"></div>
    <div class="imagemiddle"></div>
    <div class="imagemiddle"></div>
    <div class="imagemiddle"></div>
  </div>
  <div id="right"></div>
</div>

I would like to have like a three columns page where the one in the middle has a dynamic width (window resize) AND a minimum one (div #middle: min-width:400px;).

Problem is that the third column is wrapping when I resize.

I know if I replace the #middle div width:75%; by width:500px; this would work and the right column won't wrap, but I won't have a dynamic width middle column anymore...

How an I solve this?

#contentwraper {
  position: relative;
  min-width: 800px;
}

#left {
  position: relative;
  float: left;
  background-image: url("http://www.artetics.com/images/artfrontpageslideshow.png");
  background-repeat: no-repeat;
  background-position: center center;
  min-width: 128px;
  width: 12%;
  height: 128px;
}

#middle {
  position: relative;
  float: left;
  min-width: 400px;
  width: 75%;
  text-align: center;
}

#right {
  position: relative;
  float: left;
  background-image: url("http://www.emoticonswallpapers.com/avatar/art/Test-Card.jpg");
  background-repeat: no-repeat;
  background-position: center center;
  min-width: 128px;
  width: 12%;
  height: 128px;
}

.imagemiddle {
  position: relative;
  float: left;
  background-image: url("http://www.tradewindscientific.com/images/t_logo.gif");
  background-repeat: no-repeat;
  background-position: center center;
  width: 25%;
  height: 128px;
}
<div id="contentwraper">
  <div id="left"></div>
  <div id="middle">
    <div class="imagemiddle"></div>
    <div class="imagemiddle"></div>
    <div class="imagemiddle"></div>
    <div class="imagemiddle"></div>
  </div>
  <div id="right"></div>
</div>

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

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

发布评论

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

评论(1

习惯成性 2024-12-11 02:45:18

如果您希望在页面太大(或者窗口不够)时右栏溢出到文档右侧,唯一的解决方案就是表格。

否则,请尝试以下操作:3 列,中间一列宽度灵活

可以通过将 #right 移动到 #left 之后或之前来更改它的行为;或者通过在#middle上设置overflow:hidden。

http://jsfiddle.net/3UAbN/1/

If you want the right column to overflow on the right of the document when the page is too large (or the window not enough), the only solution is a table.

Else, try this: 3 columns, middle one with flexible width

You can change #right's behavior by moving it after or before #left; or by setting overflow:hidden on #middle.

http://jsfiddle.net/3UAbN/1/

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