简体   繁体   English

div容器未拉伸主要全宽div

[英]Div container is not stretching the main full width div

I want to make layout where I will have different full width backgrounds. 我想进行布局,使我将拥有不同的全角背景。 For example top is full width orange color, inside the full width div I have container that keeps everything in specific dimension (width: 1000px). 例如,顶部是全角橙色,在全角div内,我有一个容器,可以将所有内容保持在特定的尺寸(宽度:1000像素)中。 And I met a problem, The content of the container div doesnt stretch the full width div. 我遇到一个问题,容器div的内容未拉伸整个宽度div。 So right now to keep it work, I have to set in .orange and .red specific height. 所以现在要使其正常工作,我必须将.orange和.red设置为特定高度。 But this is not the solution, because right now my block has xxx heights, what If I add something like more pictures - I have to set bigger hight etc... 但这不是解决方案,因为现在我的块具有xxx高度,如果我添加更多图片,该怎么办-我必须设置更大的高度等...

Here is what I mean: 这是我的意思:

HTML 的HTML

<div class="full-width orange">
    <div class="container">
        content
    </div>
</div>

<div class="full-width red">
    <div class="container">
        content 2
    </div>
</div>

CSS 的CSS

.full-width {
    clear: both;
    width: 100%;
    overflow: hidden;
}

.container {
    width: 1000px;
    margin-left: auto;
    margin-right: auto;
    overflow: hidden;
}

.orange {
    background-color: orange;
}

.red {
    background-color: red;
}

I am sorry for my bad english. 对不起,我的英语不好。

if you put more content into your DIVs, they will stretch. 如果您在DIV中添加了更多内容,它们将会扩展。 their default height is auto ( http://www.w3schools.com/cssref/pr_dim_height.asp ) which automatically stretches the div to the height it needs to be. 它们的默认高度是auto( http://www.w3schools.com/cssref/pr_dim_height.asp ),它会自动将div拉伸到所需的高度。 if you set height to a percentage, the div will be that percentage of it's parent container. 如果将高度设置为百分比,则div将为其父容器的百分比。

here is a JS fiddle for you to play with http://jsfiddle.net/dv9ah/ i set the 这是一个JS小提琴,供您与http://jsfiddle.net/dv9ah/一起玩。

    height: auto;

in both the .red and .orange classes, but you can change them to a set height (like 100px) to see how they change. 在.red和.orange类中,但是您可以将它们更改为设置的高度(例如100px),以查看它们如何变化。

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

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