简体   繁体   English

截面直排块100%高度塌陷在固定容器中

[英]section inline-block 100% height collapsing in fixed container

I'm trying to set the height of an inline-block section (optional a div, if that should be a problem) to 100%. 我正在尝试将内联块部分(如果有问题的话,可以选择div)的高度设置为100%。 This section is contained in an fixed (position) div with height 100%. 此部分包含在高度为100%的固定(位置)div中。 body and html have a height of 100% too as you can see in the code below. 如下面的代码所示,body和html的高度也为100%。

Fiddle: http://jsfiddle.net/vxBUG/ 小提琴: http//jsfiddle.net/vxBUG/

HTML: HTML:

<div id="workWrapper">
    <section id="marketing">
        test
    </section>
    <section id="video"></section>
    <section id="web"></section>
</div>

CSS: CSS:

html, body {
    margin: 0px;
    padding: 0px;
    height: 100%;
    width: 100%;
}
#workWrapper {
    height: 100%;
    width: 100%;
    overflow: show;
    position: fixed;
    white-space: nowrap;
    z-index: 100;
}
#workWrapper section {
    width: 100%;
    height: 100%;
    display: inline-block;
    background: #aaa;
}

So, the problem is: The sections are filling the whole viewport (as I like it), BUT if I put a little content into them (like the "test"), they are collapsing to the height which is needed for containing the content. 因此,问题是:这些部分填充了整个视口(如我所愿),但是如果我在其中添加了一些内容(例如“测试”),它们就会折叠到容纳内容所需的高度。 Also, they are sticking at the bottom. 此外,它们还停留在底部。 If I remove the height in the sections they are sticking at the top. 如果我除去各部分的高度,则它们会粘在顶部。

Story behind: I want to make a div which contains 3 sections (or divs) which are as height and width as the viewport. 背后的故事:我想制作一个div,其中包含3个部分(或div),这些部分的高度和宽度与视口一样。 Then I want slide the containing div horizontal so that only one of the sections is visible. 然后,我想水平滑动包含的div,以便仅显示其中一个部分。

It's actually just aligned to the baseline, you can set the vertical align to top 它实际上只是与基线对齐,您可以将垂直对齐设置为顶部

Add this 加上这个

section {
    vertical-align: top;
}

http://jsfiddle.net/vxBUG/1/ http://jsfiddle.net/vxBUG/1/

For more info, you can check out Why is this inline-block element pushed downward? 有关更多信息,您可以查看为什么将此内联块元素向下推? there are lots to read. 有很多书要读。

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

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