如果 DIV 没有固定大小,如何防止它们换行?
我对 div 完全生气了,我很快就会完成网站的工作,但这是一件简单的事情,我不知道如何解决。
基本上我有一个菜单和一个内容 div
,内容因页面而异,我不希望它们相互环绕。
我读过几十篇文章,确切地说要为包装器添加最小宽度,但我不知道我的最小宽度是多少。有些页面只有600px宽度,而有些页面几乎有1000px,它必须用作PHP模板。
这是代码,如果有人能提供帮助,我会非常高兴,因为我对此感到完全沮丧......
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style>
div {
padding: 2px
}
div.menu {
background-color: #FAFAA0;
float: left;
}
div.content {
background-color: #9DFBA9;
float: left;
}
</style>
</head>
<body>
<div class="menu">
menu<br>menu<br>menu<br>menu
</div>
<div class="content">
The pages which have different size here. For example:
<div style="width:600px">Page one</div>
or
<div style="width:900px">Page two?</div>
</div>
<div style="clear:both">
In either way I dont wan't this two divs wrapping, but I don't know the exact size of the content page.<br> So I can't just put a min width like 1024px.<br> When they are about to wrap, the scrollbar should appear only then...<br> How can I achieve
that?
</div>
</body>
</html>
I'm completely pissed off with the divs, I'm soon to be done with website, but a simple thing I have no idea how to solve.
Basically I got a menu and a content div
s, the content is different from page to page and I don't want them to wrap against each other.
I've read dozens of posts saying exactly to put a min-width to a wrapper, but I've no idea what my min-width would be. Some pages are just 600px width, while some are almost 1000px, Its got to be used as a PHP template.
Here is the code, I'll be very glad if some one can help at all, because I'm completely frustrated with this...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<style>
div {
padding: 2px
}
div.menu {
background-color: #FAFAA0;
float: left;
}
div.content {
background-color: #9DFBA9;
float: left;
}
</style>
</head>
<body>
<div class="menu">
menu<br>menu<br>menu<br>menu
</div>
<div class="content">
The pages which have different size here. For example:
<div style="width:600px">Page one</div>
or
<div style="width:900px">Page two?</div>
</div>
<div style="clear:both">
In either way I dont wan't this two divs wrapping, but I don't know the exact size of the content page.<br> So I can't just put a min width like 1024px.<br> When they are about to wrap, the scrollbar should appear only then...<br> How can I achieve
that?
</div>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这就是你所追求的吗? http://jsbin.com/exuvoz
我附上了
.menu
和
元素,带有中的 .content
float: left
和 已更改div.content {浮动:向左; }
到div.content { 溢出:隐藏; }
。Is this what you're after? http://jsbin.com/exuvoz
I enclosed the
.menu
and.content
elements in a<div>
withfloat: left
, and changeddiv.content { float: left; }
todiv.content { overflow: hidden; }
.它适用于 Chrome、IE9 和 Firefox
It works for me in Chrome, IE9 and Firefox
请尝试一下:
所以实际上发生的是我将您的菜单 div 和内容 div 放入一个 div 中。请仔细查看我放置的内联样式。并且不使用“px”,而使用百分比。希望这有帮助。
Please try this:
So what happened actually is I put your menus div and content div into one div. Please look closely on the inline styles that I placed. And instead of using "px" use percentage. Hope this helps.
您是否尝试过在包装器上显示:表格并在菜单和内容上显示:表格单元格?
Did you try display:table on wrapper and display:table-cell on menu and content?