Html 嵌套在固定宽度 div css 中的 div 上的 100% 屏幕宽度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19063798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 13:53:16  来源:igfitidea点击:

100% Screen width on div nested in fixed width div css

csshtml

提问by imbayago

I'm trying to get a nested div to be full width on screen out of the div that it's contained/nested in.

我试图让一个嵌套的 div 在它包含/嵌套的 div 之外的屏幕上是全宽的。

http://jsfiddle.net/TheeAndre/JAdps/

http://jsfiddle.net/TheeAndre/JAdps/

<div class="fixedwidth">
    <div class="fullwidth"></div>
</div>

回答by Jan Mirus

Try

尝试

width:100vw;  

instead of

代替

width:100%;  

Check for compatibility issues: http://caniuse.com/#search=vw

检查兼容性问题:http: //caniuse.com/#search=vw

Pascalz, yes in your jsfiddle it works, but only as long as you don't specify a position other than static for your parent. In many cases you need your parent to be position:relative, so the child will relate width:100% to parent width.

Pascalz,是的,在你的 jsfiddle 中它可以工作,但前提是你没有为你的父母指定静态以外的位置。在许多情况下,您需要父级为 position:relative,因此子级会将 width:100% 与父级宽度相关联。

回答by Pascalz

try this :

尝试这个 :

.fullwidth {
    background-color:#000; 
    width:100%; 
    height:100px; 
    position:absolute; 
    z-index:999;
    left: 0;
    right: 0;
}