“vw” CSS units in calc in Chrome not working

流过昼夜 提交于 2019-11-28 09:03:19

It’s a bug, registered as Bug 94158 - calc isn't working with viewport units.

It's an old bug and has long been fixed, but if you're still supporting older versions of chrome, and specifically encountering this bug in an older version of chromium in an Android tablet you're supporting (as was my case), here's the simple way you can get around this bug:

Use a wrapper that spans the VW you're targeting, and then instead of using the viewport units in the calc(...), use 100%.

html:

<div class="container">
    <div class="inner-calc-with-viewport-units-bugged" />
</div>

css:

.container { 
    width: 100vw; //or height: 100vh, depending on your usecase
}
.inner-calc-with-viewport-units-bugged { 
    width: calc(100% - XXXXX px); //or height: calc(100% - XXpx);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!