Background Size with CSS
📖 Scenario: You are creating a simple webpage section that shows a background image. You want to control how the background image fits inside the section.
🎯 Goal: Build a webpage section with a background image and use CSS background-size property to control how the image fits inside the section.
📋 What You'll Learn
Create an HTML
<section> with a class hero.Add a background image to the
.hero section using CSS.Create a CSS variable called
--bgSize to store the background size value.Use the CSS variable
--bgSize to set the background-size property.Set the
background-repeat property to no-repeat.Set the
background-position property to center.Make sure the section has a fixed height so the background image is visible.
💡 Why This Matters
🌍 Real World
Background images are common in website headers, banners, and sections to create visual interest and branding.
💼 Career
Knowing how to control background images with CSS is essential for front-end web developers and designers to create attractive and responsive layouts.
Progress0 / 4 steps