Full Screen Backgrounds & Viewport Sizing Units vh & vw
Master viewport units and full-screen responsive layouts
Core CSS Concepts Covered
Viewport Units
Learn vh and vw units for responsive sizing relative to screen dimensions. These units provide better control than traditional percentages.
Full-Screen Backgrounds
Create hero sections that adapt to any screen size using background-size cover and viewport height units.
Vertical Centering
Master table-cell display methods for perfect vertical alignment of content within containers.
Hero images are full-screen background sections that immediately capture user attention. This design pattern is essential for modern responsive websites and requires mastery of viewport units and background properties.
Setup Requirements
Ensure you're not using the Done folder for this exercise
Observe the current black header background that needs modification
Identify the heading and anchor elements you'll be targeting
This is where you'll add the background image and styling rules
Height Units: Percentage vs Viewport
| Feature | height: 100% | height: 100vh |
|---|---|---|
| Reference Point | Parent container height | Viewport height |
| Responsiveness | Limited by content | Always full screen |
| Use Case | Content-based sizing | Full-screen layouts |
1 viewport unit equals 1/100th of the viewport. 100vh means 100% of the visible height, while 100vw means 100% of the visible width. These units are essential for responsive full-screen designs.
CSS Table Method for Vertical Centering
Set h1 to table-cell
Change display property to table-cell and add vertical-align: middle
Set header to table
Parent container must use display: table for table-cell to work properly
Add full width
Set width: 100% on header to prevent shrinking to content width
Using text-indent: -9999px hides text while keeping it accessible to screen readers. The background image provides the visual element while maintaining semantic HTML structure.
left: calc(50% - 20px)
Font Size Scaling with Viewport Width
Using Viewport Width (vw) for Typography
The 18vw font size looks great on mobile but dominates desktop screens. Adding a media query at 600px breakpoint with 8vw creates better proportions across all screen sizes.
Key Takeaways
