Asked • 04/04/19

CSS background image to fit width, height should auto-scale in proportion?

I have body { background: url(images/background.svg); }The desired effect is that this background image will have width equal to that of the page, height changing to maintain the proportion. e.g. if the original image happens to be 100*200 (any units) and the body is 600px wide, the background image should end up being 1200px high. The height should change automatically if the window is resized. Is this possible?At the moment, Firefox looks like it's making the height fit and then adjusting the width. Is this perhaps because the height is the longest dimension and it's trying to avoid cropping? I *want* to crop vertically, then scroll: no horizontal repeat.Also, Chrome is placing the image in the centre, no repeat, even when `background-repeat:repeat` is given explicitly, which is the default anyway.

1 Expert Answer

By:

Xavier P. answered • 04/04/19

Tutor
5.0 (98)

Creatively Open-minded tutor in Programming, Math and The Arts

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.