Parent container with child elements position: absolute does not size properly to fit the children
Really hard to put my thoughts into words but I have a container essentially and I have two h3's inside of it which I want to paginate. I have it working as I want but only when I explicitly tell the container its height and width. I understand its behavior because position absolute pulls it out of the flow but that means without explicit width and height my container is a tiny blob. This impacts my reactiveness of the website as when the width of the device increases or decreases text starts to overflow instead of the container adapting to fit the content
If I remove position absolute and try to explicitly set the width of the child it doesn't work (I try set 1200px)
css:
html react component (You can provide Vanilla JS solution I can convert)
Let me know if you need any more information
13 Replies
why make the .first and .second absolute?, you can just make them regular childs of the .paginatedContainer
Well as shown in the video when i do that they lock into some 612px width and I cannot change it no matter what. Setting
width: 100%, width: 200%, width: 1000px, width: 1000000px
nothing changes it unless its less than that magical 624px
or whatever it is.i dont really understand tbh. what about this
https://codepen.io/MarkBoots/pen/vYwPzap?editors=1100
Ends up looking like this when i update my css to this:
Theres a gap the same size as the child element between the two children idk why
gonna need to see more than this. can you make a codepen/sandbox
Okay sorry. Had to set up a codepen and get the layout working
https://codepen.io/dennis777-the-builder/pen/PovLMRe
ah okay, the gap is because of the translate. it's not nessesarry anymore to translate the second one to the right by default. it already is thanks to the grid
https://codepen.io/MarkBoots/pen/WNBWbyL
Sweet man thats exactly it! Truly appriciate it. Off the top of your head would you know how I can prevent the container from expanding past what it needs? (I'm using
max-width: 1260px
in paginated and it works but I was wondering if it can to do automatically)you could do width: fit-content
doesnt seem to do it
ah no, that indeed wont work, because the children depend on the width
i've updated the pen with a possible sollution
Ah alright no worries I really appreciate your help!