The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS CSS Layouts – Fixed Sidebar with Background that extends to edge of window

  • This topic is empty.
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)
  • The forum ‘CSS’ is closed to new topics and replies.