Member-only story
Why Your Div Doesn’t Fit: A Simple Look at the Box Model
Alright, in last CSS related post we talked about relative units and today we going to talk about Box Model.
Imagine you’re moving into a new apartment. You’ve got furniture of all shapes and sizes: sofas, bookshelves, coffee tables. Now, arranging them can get messy fast — unless you know exactly how much space each one needs, right?
Well, in CSS, each element on your page is like a piece of furniture, and the browser needs rules to figure out exactly how to place them. This is the idea behind box model where every element on a webpage is treated like a rectangular box. Understanding this model is key before jumping into fancy layouts like grids or flexboxes.
Alright, let’s explain this with an actual example! You’ll have a header at the top, with a main content area on the left and a smaller sidebar on the right. I’ve purposely kept the layout simple and clear, so you can easily understand how each element is sized and positioned on the page. By the time we’re done, you’ll have something similar to the example shown here.