I am facing an issue with scrolling CSS on my mobile devices. I have attached an image. due to the 100vh height, I can’t scroll to my main body. the bottom part gets obscured by the bottom nav. then I removed the 100vh but it still isn’t working.
import React, { ReactNode, useEffect } from "react";
import Header from "../LeftSide/Header";
import LeftSide from "../LeftSide/LeftSide";
import "./Layout.css";
interface Props {
children?: ReactNode;
}
const Layout = ({ children, ...props }: Props) => {
const [collapsed, setCollapsed] = React.useState(false);
const handleValueChange = (value: any) => {
setCollapsed(!collapsed);
};
useEffect(() => {
window.scrollTo(0, 0);
if (window.innerWidth <= 1000) {
setCollapsed(true);
}
}, []);
return (
<>
<div className='d-flex' style={{ height: "100vh", overflow: "hidden" }}>
<div className='mobileSidebar'>
<LeftSide collapsed={collapsed} setCollapsed={setCollapsed} />
</div>
<div style={{ width: "100%" }}>
<Header onValueChange={handleValueChange} />
<div {...props}>{children}</div>
</div>
</div>
</>
);
};
export default Layout;
2
Answers
It’s hard to work with incomplete code but i made an example in html/css with how you can solve this problem:
overflow-y: auto
makes sure the.content
div is scrollableInstead of using height: 100vh, use min-height with a calc() function to subtract the height of the mobile browser’s navigation bar. This ensures that your layout is responsive on mobile devices.
Adjust Layout css too
This should fix the scrolling issue and ensure the layout works properly on all devices