admin管理员组文章数量:1326447
I have to build a navbar that slides from the right side of the screen. It has to cover the whole screen. The problem is that in mobile phones, browsers like chrome have this toolbar at the bottom, which hides some part of the page. Which is not feasible as I also have to display some contact information at the bottom.
The fix for this was using -webkit-fill-available. But, the css for my navbar and the hamburger menu row is :
.hamburger-row {
position: fixed;
height: 75px;
}
And for navigation menu div...
.nav-menu-div {
position: fixed;
height: calc(100vh - 75px);
}
But to introduce -webkit-fill-available, I have to do something like
height: calc(-webkit-fill-available - 75px);
which is not possible in css.
Is there any workaround?
I have to build a navbar that slides from the right side of the screen. It has to cover the whole screen. The problem is that in mobile phones, browsers like chrome have this toolbar at the bottom, which hides some part of the page. Which is not feasible as I also have to display some contact information at the bottom.
The fix for this was using -webkit-fill-available. But, the css for my navbar and the hamburger menu row is :
.hamburger-row {
position: fixed;
height: 75px;
}
And for navigation menu div...
.nav-menu-div {
position: fixed;
height: calc(100vh - 75px);
}
But to introduce -webkit-fill-available, I have to do something like
height: calc(-webkit-fill-available - 75px);
which is not possible in css.
Is there any workaround?
Share Improve this question asked May 31, 2020 at 10:27 ManishManish 1331 gold badge2 silver badges8 bronze badges 1- 1 Nope calc requires a value and you don't have one. – Paulie_D Commented May 31, 2020 at 10:34
4 Answers
Reset to default 6There's a hacky workaround but it needs to use Javascript to aid CSS. It's been well described here: https://css-tricks./the-trick-to-viewport-units-on-mobile/#css-custom-properties-the-trick-to-correct-sizing
In your website you need to add this JS:
function appHeight() {
const doc = document.documentElement;
// Multiplied by 0.01 to get a percentage value
doc.style.setProperty('--vh', (window.innerHeight*.01) + 'px');
}
window.addEventListener('resize', appHeight);
appHeight();
and for your case in CSS it will look like:
.nav-menu-div {
position: fixed;
height: calc(100vh - 75px);
height: calc(calc(var(--vh, 1vh) * 100) - 75px);
}
CSS only work around using a negative margin. This tries to target mobile browsers. It will catch desktop browsers too if they are sized small and doesn't perform right on small window desktop chrome, but it generally good enough.
.wrapper {
min-height: 100vh;
margin-bottom: -150px;
padding-bottom: 150px;
}
@media only screen and (max-device-width: 480px) {
.wrapper {
min-height: -webkit-fill-available;
}
}
.footer {
height: 150px;
}
<div class="wrapper">
Main Content
</div>
<div class="footer">
Footer
</div>
The 2024 answer for the specific use case you asked for -webkit-fill-available
should look like this:
Use 100dvh
instead. It's the new unit introduced for dynamic viewport units and is supported by all major browsers.
While we still do not have a 99% coverage yet, I would remend introducing it with a fallback still like this:
.nav-menu-div {
position: fixed;
height: calc(100vh - 75px);
height: calc(100dvh - 75px);
}
Also you might have a look at this blog post for more details in a pact format.
if your problem is that the div isn't showing do you need to put the width property and the background-color (of image) property , if you don't have this, the div isn't showing.
Hope I help you
本文标签: javascriptHow to do calc function on vendorprefixed properties in cssStack Overflow
版权声明:本文标题:javascript - How to do calc function on vendor-prefixed properties in css? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742214337a2434289.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论