Skip to main content


This topic contains 2 replies, has 2 voices, and was last updated by  amits97 3 months, 1 week ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #282801


    Here is the layout I am trying to achieve:

    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:

    I got the layout fully working in this fiddle:

    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?



    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.



    Thank you for the explanation. That makes a lot of sense :)

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

icon-link icon-logo-star icon-search icon-star