Search code examples
csscreate-react-app

Background image will not fit in the whole page in App.css in create-react-app


I'm not sure why but any image I choose for the page's background is never 100% entirely shown. I'm not sure if create-react-app has something to do with it or what but there is always some part of the image that is overflowing and gets cut from the page.

body{
    background-image: url("https://images.unsplash.com/photo-1516849677043-ef67c9557e16?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80");
    background-size: 100%;
    background-position: center;
    height: 100vh;
}

I need the image to be shown in its entirety. background-size: 100% doesn't seem to do it inside create-react-app for some reason.


Solution

  • Basically, background-size: 100% will fill the screen with the image, and crop it if necessary.

    I think what you want is to see the whole image. You should use contain for that:

        html {
         width: 100%;
         height: 100%;
         background: red url('http://media.gettyimages.com/photos/groningen-city-view- picture-id588880579?s=612x612') no-repeat center;
         background-size:contain;
        }

    jsfiddle