Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS

Japneet Singh
Japneet Singh
4,675 Points

how to size the background image in css

i want my background image to cover all of my header. so i used the cover property but it makes my image(.svg) bigger but the whole image is not visible.

2 Answers

Hi Japneet,

Maybe

background-size: contain;

Would better suit?

Hope that helps.

KB :octopus:

Japneet Singh
Japneet Singh
4,675 Points

nah tried that too but it pushes the image to left and its size remains the same that is 800*800

I'm not sure how you have your header set up, but here is a great resource for scaling background images:

MDN

I hope this helps, if you need more help please post the HTML and CSS of the header, so we can see whats going on.

Japneet Singh
Japneet Singh
4,675 Points
<header>
    <h1>Welcome to Central Perk</h1>
</header>
    header{
        height: 640px;
        background-image: url('C:/Users/Japneet/Desktop/minimalwall/pizza.svg');
        background-size: cover;
        background-repeat: no-repeat;
        background-position: center;
    }

You should read the documentation and if you get stuck, please ask where you are stuck. You need to know what your img size is as well, and if need be use photoshop to edit the size.

Japneet Singh
Japneet Singh
4,675 Points

i used this as well

background size : 1000px 640px;

but the problem i am facing is that the width is not scaling only the height is

you don't have a width set on on your header. have you tried to use percents? also you need to know what size the img is.