How do I make a picture fit into the background of my webpage using CSS? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How do I make a picture fit into the background of my webpage using CSS?

I used the background-image: {...} property but it didn't fit into my browser. The image got cut in half vertically and repeated itself horizontally. Now I'm curious to know if there's a specific height and width to fit in perfectly.

15th Aug 2018, 6:38 PM
Hendrix Ejegi
Hendrix Ejegi - avatar
6 Answers
+ 7
try these background-size: 100% 100%; background-repeat: no-repeat; and optionally background-attachment: fixed;
15th Aug 2018, 6:47 PM
Just A Rather Ridiculously Long Username
+ 2
No problem :) However, try googling these next time, this was the first result
15th Aug 2018, 6:52 PM
Just A Rather Ridiculously Long Username
+ 1
Lovely
15th Aug 2018, 11:28 PM
Decodeworms Olamilekan
Decodeworms Olamilekan - avatar
0
It worked...Thanks
15th Aug 2018, 6:49 PM
Hendrix Ejegi
Hendrix Ejegi - avatar
0
Background-cover:fit; Background-repeat:no-repeat;
16th Aug 2018, 10:54 AM
Kingsley Osuji
0
just try background-size: cover; background-repeat: no-repeat;
16th Aug 2018, 7:52 PM
Joseph Edore