自动宽度、百分比和固定宽度导致 DIV 换行
我想要一个三列页面,其中中间的一个具有动态宽度(窗口调整大小)和一个最小宽度(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望在页面太大(或者窗口不够)时右栏溢出到文档右侧,唯一的解决方案就是表格。
否则,请尝试以下操作: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/