Understanding the Box Model and Page Layout
Control spacing and build dependable layouts with Flexbox and Grid.
Control spacing and build dependable layouts with Flexbox and Grid.
What you will learn
- Explain content padding border and margin
- Use Flexbox for one-dimensional layout
- Use Grid for rows and columns
Before you begin
Create a separate practice folder and use non-sensitive sample content. Keep backup copies before restructuring files. Browser interfaces vary, so use the browser developer tools available on your computer.
Use the box model
Every element has content surrounded by padding, border and margin. Use box-sizing border-box so declared widths include padding and borders.
Margin creates space outside an element, while padding creates space inside it. Avoid fixed heights for text containers because content may overflow.
Arrange with Flexbox
Flexbox works well for navigation, button groups and rows whose items need alignment or flexible spacing. The container controls direction, wrapping and alignment.
Allow wrapping where content may not fit. Use gap for consistent spacing instead of unpredictable margins on each child.
Build with Grid
CSS Grid is useful for cards and page regions arranged in rows and columns. Fractional units share available space, and minmax can keep tracks flexible.
Choose layout tools according to content, not a particular screen size. Source order should remain logical when CSS is unavailable.
Guided practice
- Apply border-box sizing to the practice site.
- Build a wrapping navigation row with Flexbox.
- Create a responsive card grid with Grid and gap.
Knowledge check
- What is the difference between margin and padding?
- When is Flexbox a good choice?
- Why should fixed heights be avoided for text?
Completion standard
Continue when you can complete the guided practice and explain the knowledge-check answers in your own words.
Web Design for Beginners
Continue through the course in order. New published parts appear here automatically.
- 1Planning a Useful Website
- 2Creating Your First HTML Page
- 3Adding Links Images and Page Navigation
- 4Styling Pages with CSS
- 5Understanding the Box Model and Page Layout
- 6Designing Responsive Mobile Friendly Pages
- 7Designing Accessible and Inclusive Interfaces
- 8Building Clear and Safe Web Forms
- 9Testing Performance Search and Browser Quality
- 10Publishing and Completing a Small Website