修复了包含div的溢出的位置div

时间:2014-07-10 08:47:37

标签: html css css3

我怎样才能得到它,所以div .inner涵盖了整个屏幕? jsfiddle

HTML:

<div class="outer">
   <div id="inner">This should cover the entire screen</div>
</div>

CSS:

.outer {
     margin: auto;   width: 100%;
     top: 0; bottom: 0;
     height: 100vh;
     max-width: 20rem;
     background: blue;
}

.inner {
    top: 0; bottom: 0; left: 0; right: 0;
    position: fixed;
    background: gray;
    z-index: 2
}

4 个答案:

答案 0 :(得分:3)

css中,它应为#inner

#inner {
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    position: fixed;
    background: gray;
    z-index: 2;
}

答案 1 :(得分:1)

将内部div id的属性更改为class

<强> HTML:

<div class="outer">
   <div class="inner">This should cover the entire screen</div>
</div>

<强> CSS:

.outer {
     margin: auto;   width: 100%;
     top: 0; bottom: 0;
     height: 100vh;
     max-width: 20rem;
     background: blue;
}

.inner {
    top: 0; bottom: 0; left: 0; right: 0;
    position: fixed;
    background: gray;
    z-index: 2
}

答案 2 :(得分:1)

.inner替换为您的css文件中的#inner,也不需要在内部css中提供right:0;bottom:0;

答案 3 :(得分:0)

尝试将宽度设置为最小宽度。

.outer {
     margin: auto;
     min-width: 100%;
     top: 0;
     bottom: 0;
     height: 100vh;
     max-width: 20rem;
     background: blue;
}