简体   繁体   English

设置宽度div,防止其他div跨越100%宽度

[英]Set width div preventing other divs to span 100% width

I seem to be having some trouble with 100% widths. 我似乎遇到了100%宽度的麻烦。 I have 3 divs, header, content and footer which are relatively positioned. 我有3个div,标题,内容和页脚相对定位。 I have set a width of 600px on the header and a width of 100% on the content and footer. 我在标题上设置了600px的宽度,在内容和页脚上设置了100%的宽度。 However if I resize the browser when I use the horizontal scrollbar the 100% width divs are cut off and don't go all the way across to match the 600px div...how can I fix this? 但是,如果我在使用水平滚动条时调整浏览器的大小,则会切断100%宽度的div,并且不会完全匹配600px div ...我该如何解决这个问题?

CSS CSS

#header {
    position: relative;
    width: 620px;
}

#content, #footer {
    position: relative;
    width: 100%;
}

HTML HTML

<div id="header"></div>
<div id="content"></div>
<div id="footer"></div>
<div id = "container">
    <div id="header"></div>
    <div id="content"></div>
    <div id="footer"></div>
</div>


#container {min-width:620px;}

See example: http://jsfiddle.net/calder12/xN2PV/3/ 参见示例: http//jsfiddle.net/calder12/xN2PV/3/

Point to note. 要点注意。 min-width is not supported in IE6. IE6不支持min-width。 I doubt this matters, if it does you'll need a different solution. 我怀疑这很重要,如果确实如此,你需要一个不同的解决方案。

Set width to "auto" for #content and #footer. 为#content和#footer设置宽度为“auto”。 Divs, being block elements, will automatically consume 100% of the available width (sans margin if set) in their immediate parent element. 作为块元素的Div将在其直接父元素中自动消耗100%的可用宽度(如果设置则没有边距)。

As such, if #content and #footer are contained within #header or any other explicitly sized element , then they will never be wider than the specified width. 因此,如果#content和#footer包含在#header 或任何其他显式大小的元素中 ,那么它们将永远不会宽于指定的宽度。

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

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