I'm creating a React PWA for a client using Tailwind CSS and I want to achieve a layout in which there's a header fixed to the top of the screen and a navbar fixed to the bottom of the screen. In between I'll display scrollable content of dynamic size.
I've been struggling with this problem for the most part of the day and I'm following the instructions on this answer as well as the code it provided here.
I though I got it, as I implemented all the recommended classes in the relevant components and I got this result on my browser dev tools:
However, I got curious and decided to open the page on my phone. This is the result there and, as you can see, neither of the desired elements are actually fixed to the screen:
At this point I'm completely lost. I've tried using className={fixed}
in the Navbar, but it ends up clipping part of the content even when adding margin or padding to either the navbar or the content.
How can I fix both header and navbar to the screen while keeping the content scrollable?
These are the relevant parts of my code:
App.js:
function App() {
return (
<Router>
<div className='flex flex-col h-screen overflow-hidden'>
<Header></Header>
<div className='MainContent flex-1 overflow-y-scroll py-2 mx-2'>
<Routes>
<Route path="/" element={<OrderView />} />
<Route path="/DeliverymenView" element={<DeliverymenView />} />
<Route path="/InventoryView" element={<InventoryView />} />
<Route path="/RouteGenerationView" element={<RouteGenerationView />} />
<Route path="/AdministrativeView" element={<AdministrativeView />} />
<Route path="*" element={<ErrorView />} />
</Routes>
</div>
<Navbar></Navbar>
</div>
</Router>
);
}
Header.js:
const Header = () => {
return (
<div className="Header shadow-md bg-white w-full ">
<CurrentPage />
</div>
)
}
Navbar.js:
function Navbar() {
return (
<div className="Navbar w-full flex flex-row gap-x-2 justify-evenly py-1 bg-white drop-shadow-md-top">
<Link to="/">
<MdShoppingCart className="text-zinc-400 text-5xl "></MdShoppingCart>
</Link>
<Link to="/DeliverymenView">
<MdPerson className="text-zinc-400 text-5xl "></MdPerson>
</Link>
<Link to="/InventoryView">
<MdViewList className="text-zinc-400 text-5xl "></MdViewList>
</Link>
<Link to="/RouteGenerationView">
<MdDeliveryDining className="text-zinc-400 text-5xl "></MdDeliveryDining>
</Link>
</div>
)
}