CSS Styling for Optimal Web Layout
Master CSS Layout Techniques for Professional Web Design
This exercise builds on Exercise 3b of the Revolution Travel website. If you haven't completed the previous exercise, ready-to-use starter files are provided to help you jump in at this point.
HTML Structure Elements
Header & Navigation
Contains the main site branding and navigation menu. These elements are styled differently from the main content area.
Main Content Area
Houses the primary page content including H1, H2, and H3 headings. Currently too wide and needs CSS constraints.
Footer Section
Bottom page content that should align with the main content width for visual consistency.
Embedded CSS vs External CSS
Width Units: Pixels vs Percentages
| Feature | Fixed Pixels | Percentage Width |
|---|---|---|
| Responsiveness | Static across all screens | Adapts to screen size |
| Control | Precise pixel control | Relative to container |
| Mobile Friendly | May overflow on small screens | Scales with device |
| Best Use Case | Fixed layouts, precise design | Responsive fluid layouts |
Creating Responsive Width with Max-Width
Set Percentage Width
Start with 90% width to create flexible sizing that adapts to different screen sizes while maintaining margins
Add Max-Width Constraint
Set max-width to 800px to prevent content from becoming too wide on large screens
Center with Auto Margins
Use margin-left: auto and margin-right: auto to center the content horizontally on the page
Don't Repeat Yourself - Use comma-separated selectors like 'main, footer' to apply the same styles to multiple elements, reducing code duplication and making maintenance easier.
Images come in at their native size by default. If they're small, they're small. If they're big, they're big, and they are a fixed size.
Always include 'img { max-width: 100%; }' in your CSS. This prevents images from overflowing their containers and is fundamental for responsive design.
Responsive Design Concepts
Fluid Layout
Uses flexible units like percentages that change based on screen size. Creates adaptable designs that work across devices.
Responsive Web Design
Involves media queries and breakpoints to create different layouts for different screen sizes. More advanced than fluid design.
Mobile Optimized
Design approach that ensures websites work well on mobile devices through flexible layouts and appropriate sizing.
Font Weight Values
Typography Hierarchy Setup
Set Base Font Family
Apply sans-serif font family to the body element to establish the base typography for the entire page
Style All Headings
Use grouped selectors (h1, h2, h3) to apply consistent color and remove default bold styling
Define Individual Sizes
Set specific font sizes for each heading level: H1 at 28px, H2 at 23px, maintaining visual hierarchy
Default vs Custom Paragraph Spacing
| Feature | Browser Default | Custom Styling |
|---|---|---|
| Font Size | 16px | 16px (kept) |
| Line Height | Default spacing | Increased for readability |
| Bottom Margin | 16px | 22px |
When two elements with margins are adjacent, the margins collapse to the larger of the two values rather than adding together. This prevents excessive spacing between elements.
This lesson is a preview from our Web Development with HTML & CSS Course Online (includes software) and Full-Stack Web Development Certificate Online (includes software). Enroll in a course for detailed lessons, live instructor support, and project-based training.
Key Takeaways