Multiple Backgrounds & Viewport Sizing Units (vw)
Master advanced CSS techniques for modern web design
Core Concepts You'll Master
Multiple Backgrounds
Learn to layer multiple background images and effects on a single HTML element using comma-separated CSS values.
Gradient Overlays
Discover how to colorize photos by overlaying transparent gradients for stunning visual effects.
Viewport Units
Master responsive typography that scales automatically with screen size using vw units.
This tutorial uses the Tahoe Multiple Backgrounds folder from Desktop > Class Files > Advanced HTML CSS Class. Make sure you have these files ready before starting.
Adding Multiple Backgrounds
Open Project Files
Navigate to the Tahoe Multiple Backgrounds folder and open index.html and main.css in your code editor.
Add Pattern Background
In the header rule, add the pattern.svg background before the existing masthead.jpg background, separated by a comma.
Test the Result
Save and reload the browser to see the blue diamond pattern layered on top of the background photo.
The first background in the comma-separated list appears on top, the second appears underneath, and so on. This stacking order is crucial for achieving the desired visual effect.
Because CSS gradients are background images, you can combine a background image and a background gradient on a single element!
Creating Gradient Overlays
Replace Pattern with Gradient
Change the pattern.svg to a linear-gradient with RGBA color values from cyan to green.
Adjust Transparency
Change the alpha values from 1 to 0.6 to make the gradient 60% transparent, allowing the background image to show through.
Fine-tune the Effect
Experiment with different alpha values and colors to achieve your desired visual balance.
Fixed vs Viewport Units
| Feature | Fixed Pixels | Viewport Units (vw) |
|---|---|---|
| Responsiveness | Static size | Scales with screen |
| Mobile Experience | Often too large | Proportional sizing |
| Desktop Experience | Often too small | Scales appropriately |
| Maintenance | Multiple breakpoints | Automatic scaling |
Font Size Calculation Examples
Implementing Responsive Typography
Set Base Viewport Size
Change h1 font-size to 11vw for mobile-first responsive scaling.
Add Medium Screen Breakpoint
At 600px and above, reduce font-size to 7.5vw to prevent text from becoming too large.
Optimize for Large Screens
At 1100px and above, set font-size to 6vw for optimal desktop viewing experience.
The vw unit represents 1% of the viewport width. So 11vw on a 320px screen equals 320 × 0.11 = 35.2px, while the same value on a 1200px screen equals 132px.
Key Takeaways
