0

I am new to HTML/CSS and I am having trouble making the background image of my div cover the full screen. I have used background-size:cover but it still has large margins on the left and right of the screen.

HTML:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta viewport="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
        <link rel="stylesheet" href="styles.css">
    </head>
    <body>
        <div class="container">
        </div>
    </body>
<html>

CSS

.container{
    height:100vh;
    width:100vw;
    background-image:url("city.jpeg");
    background-repeat:no-repeat;
    background-size:cover;
    background-position:center;
    opacity: 0.8;
}
chibiw3n
  • 357
  • 2
  • 15

3 Answers3

0

Please try using img: {width: 100% height:100%}. Your best approach would be to inspect the element and check if the div that contains the image is restricitng its size or not. You can use firefox to inspect (I just prefer it over chrome as it shows the size of any element better visually).

AZAF
  • 67
  • 7
0

By default, the body has a margin around it. Try this:

body {
  margin: 0;
}
Anna Azzam
  • 252
  • 2
  • 7
0

Use following code:

.background-image {
    width: 100vw;
    height: 100vh;
}
Kourosh
  • 91
  • 7