Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7508221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:38:35+00:00 2026-05-29T22:38:35+00:00

I have body { background: url(images/background.svg); } The desired effect is that this background

  • 0

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 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T22:38:37+00:00Added an answer on May 29, 2026 at 10:38 pm

    There is a CSS3 property for this, namely background-size (compatibility check). While one can set length values, it’s usually used with the special values contain and cover. In your specific case, you should use cover:

    body {
        background-image:    url(images/background.svg);
        background-size:     cover;                      /* <------ */
        background-repeat:   no-repeat;
        background-position: center center;              /* optional, center the image */
    }
    

    Eggsplanation for contain and cover

    Sorry for the bad pun, but I’m going to use the picture of the day by Biswarup Ganguly for demonstration. Lets say that this is your screen, and the gray area is outside of your visible screen. For demonstration, I’m going to assume a 16×9 ratio.

    screen

    We want to use the aforementioned picture of the day as a background. However, we cropped the image to 4×3 for some reason. We could set the background-size property to some fixed length, but we will focus on contain and cover. Note that I also assume that we didn’t mangle the width and/or height of body.

    contain

    contain
    

    Scale the image, while preserving its intrinsic aspect ratio (if any), to the largest size such that both its width and its height can fit inside the background positioning area.

    This makes sure that the background image is always completely contained in the background positioning area, however, there could be some empty space filled with your background-color in this case:

    contain

    cover

    cover
    

    Scale the image, while preserving its intrinsic aspect ratio (if any), to the smallest size such that both its width and its height can completely cover the background positioning area.

    This makes sure that the background image is covering everything. There will be no visible background-color, however depending on the screen’s ratio a great part of your image could be cut off:

    cover

    Demonstration with actual code

    div > div {
      background-image: url(https://i.stack.imgur.com/r5CAq.jpg);
      background-repeat: no-repeat;
      background-position: center center;
      background-color: #ccc;
      border: 1px solid;
      width: 20em;
      height: 10em;
    }
    div.contain {
      background-size: contain;
    }
    div.cover {
      background-size: cover;
    }
    /********************************************
     Additional styles for the explanation boxes 
    *********************************************/
    
    div > div {
      margin: 0 1ex 1ex 0;
      float: left;
    }
    div + div {
      clear: both;
      border-top: 1px dashed silver;
      padding-top:1ex;
    }
    div > div::after {
      background-color: #000;
      color: #fefefe;
      margin: 1ex;
      padding: 1ex;
      opacity: 0.8;
      display: block;
      width: 10ex;
      font-size: 0.7em;
      content: attr(class);
    }
    <div>
      <div class="contain"></div>
      <p>Note the grey background. The image does not cover the whole region, but it's fully <em>contained</em>.
      </p>
    </div>
    <div>
      <div class="cover"></div>
      <p>Note the ducks/geese at the bottom of the image. Most of the water is cut, as well as a part of the sky. You don't see the complete image anymore, but neither do you see any background color; the image <em>covers</em> all of the <code>&lt;div&gt;</code>.</p>
    </div>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a background that repeats and positions like this: body { background-image: url(images/background.jpg);
I have this background, the css code is: body { background: #FFF url('images/bg.png') no-repeat
Ok so I have a Background background-image: url('images/body.png'); now I want to overlay a
I have this in my CSS file: body {style.css (line 3) background:#CDF8FF url(images/final_bg.jpg) no-repeat
I have a background on a page body that is an image which I
Currently I have: body { background-image:url('images/background'); background-color:#000; background-position:center; background-repeat:repeat-y; padding-right: 75px; padding-left: 75px; }
I have an android app that has has this css for the body background:
I have a problem with jQuery parallax effect for my body's background. Here is
I have a page where the body is set to a background colour. I
I have a background image which I apply to the body. The image is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.