I have 2 divs sidebar and main div, when postion fixed is appplied to sidebar the and main div is taking the whole screen width.I want to fixed sidebar and the main div to taking remaing width space for the div. Example if sidebar is taking 4% width then main div should take 96% width, but its taking 100%width
<div className="flex items-start">
<aside className="bg-red-200 fixed h-[100vh]">
<ul>
<li> Home</li>
<li> About</li>
<li> About</li>
</ul>
</aside>
<main className="overflow-y-auto">
<Navbar />
<Outlet />
</main>
</div>
```
3
Answers
When you apply
position: fixed
to an element, it’s taken out of the normal document flow (as if that element is never there). So the following elements will start taking place of thefixed
element.Fix
You can solve this by giving pl(padding left) utility class to main section.
Demo – https://play.tailwindcss.com/JFDFRevhg2
When you apply position fixed then The element is removed from the normal document flow, and no space is created for the element in the page layout.
so if you want to keep the space of fixed element then minus the width of it from main div.