I need to make a bootstrap column fixed position (col-md-4
).
This is for a shop layout with 2 columns:
- Shop content (long & scrollable)
col-md-8
- Cart content (short & fixed so it stays visible while scrolling the shop content)
col-md-4
I'm not sure how to achieve this properly in bootstrap.
Here is the desired outcome:
Currently, I tried setting the col-md-4
position to fixed using the css
property, but it's not perfect.
As shown in this image, when the col-md-4
position is fixed, its width (33% for col-md-4
) is wider than intended.
Normally, col-md-4
has a 33% width css property based on its parent container.
But when the position is fixed, for some reason, the 33% is calculated based on the screen width. So if the screen resolution is 2500px, it would be 33% of 2500px instead of the container's 1170px, causing the col-md-4
to be wider and overflow the container.
I could potentially fix this in javascript by recalculating the width, but I'm wondering if there is a better way to handle this in bootstrap (which I believe there is).