Difference between Width:100% and width:100vw?

后端 未结 3 2087
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 00:31

I have to fit an iframe in screen height. Obviously, I wanted 100% as in width but, since that doesn\'t work, I used 100vh. But vh like vw is not exactly 100%. In my laptop

3条回答
  •  攒了一身酷
    2020-11-29 01:31

    You can solve this issue be adding max-width:

    #element {
       width: 100vw;
       height: 100vw;
       max-width: 100%;
    }
    

    When you using CSS to make the wrapper full width using the code width: 100vw; then you will notice a horizontal scroll in the page, and that happened because the padding and margin of html and body tags added to the wrapper size, so the solution is to add max-width: 100%

提交回复
热议问题