简体   繁体   English

防止浮动的div包装到下一行

[英]Prevent floated divs from wrapping to next line

Here is my site, first of all. 这是我的网站,首先。

You'll notice that underneath the divider bar in the middle of the page, there are three columns, one with a form, one with text, one with links. 您会注意到,在页面中间的分隔栏下方,有三列,一列带有表单,一列带有文本,一列带有链接。

Now, resize the window to slightly smaller, and the right div will drop down to the next line. 现在,将窗口调整为稍微小一些,右边的div将下拉到下一行。

Is there anyway to just not display that? 反正有没有显示那个? So, the divs will adjust (I have a liquid layout) up to the point where they won't fit, then, instead of wrapping the div down to the next line, it just won't be displayed? 因此, divs会调整(我有一个液体布局)直到他们不适合的点,然后,而不是将div包装到下一行,它只是不会显示?

You can also achieve that with CSS only. 您也可以只使用CSS实现。

Just assign the following CSS attributes to #row4: 只需将以下CSS属性分配给#row4:

#row4 {
    min-width:1202px; /* the exact value depends on the sum of the width of your 3 column boxes */
    overflow:hidden;
}

This differs slightly from your intended solution, since the right box will stay partly visible when sizing down the window and will not immediately disappear completely. 这与您的预期解决方案略有不同,因为在调整窗口大小时右侧框将保持部分可见,并且不会立即完全消失。

Please be aware that min-width won't work in IE6. 请注意,最小宽度在IE6中不起作用。 However, there are several ways to emulate the min-width property, if you need to support old IEs: 但是,如果需要支持旧的IE,有几种方法可以模拟min-width属性:

http://www.thecssninja.com/xhtml/ie6-min-width-solutions http://www.thecssninja.com/xhtml/ie6-min-width-solutions

You can give them a wrapper div with a min-width set and force it to use a horizontal scrollbar if it gets too small. 您可以为它们提供一个包含最小宽度设置的包装div,并强制它使用水平滚动条(如果它太小)。 The nice thing about a wrapper div is you can give it a max-width as well and keep things from getting wonky on super huge monitors. 关于包装器div的好处是你可以给它一个最大宽度,并防止在超大型显示器上变得不稳定。

I'm not a fan of horizontal scrollbars, but it beats completely removing content. 我不是水平滚动条的粉丝,但它完全删除了内容。

Ok here is what you should do 好的,这是你应该做的

Wrap all three floated division on a parent div, something like this 在父div上包裹所有三个浮动分区,类似这样

<div id="parent">
    <div class="form">......</div>
    <div class="text">......</div>
    <div class="links">.....</div>
</div>

Now to solve your problem give a fixed height to the parent div like 现在解决你的问题给parent div一个固定的高度就好了

#parent { height:400px;clear:both; }

您必须使用Javascript来获取视口的宽度,然后将包装的div的显示属性更改为display:none,以便在浏览器宽度太小时不显示它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM