February 12, 2019 at 3:45 pm #282801
Here is the layout I am trying to achieve: https://i.stack.imgur.com/izmN9.png
Looks simple enough right? But take a good look at the sidebar: the content has to constrained within the parent container, but the background extends to the end.
Now I know this is possible using some hacky absolute positioning CSS, but I saw something similar being done on the React blog here: https://reactjs.org/blog/2019/02/06/react-v16.8.0.html
I got the layout fully working in this fiddle: https://jsfiddle.net/w4gkdLv3/3/
The magic seems to be happening here:
margin-right: -999px; padding-right: 999px;
Seems like a super neat CSS trick. Can anyone explain why this works?February 12, 2019 at 10:46 pm #282810
Negative margin pulls the container boundary way past its original position.
Padding puts internal content back into its original position.
It’s a way of extending background colours to the edge of the screen – one of the original ways of achieving seemingly equal height columns (or in this case, width) with CSS before you could fake it with pseudo elements, or do it ‘properly’ with flexbox.February 13, 2019 at 1:21 pm #282842
Thank you for the explanation. That makes a lot of sense :)
You must be logged in to reply to this topic.