0

When I run my code in my laptop, then the img is showin full screen. But when I run it on a bigger screen size then it comes double: enter image description here

This is my css code I use:

body {

  background: url(pic.jpg); 
  background-size: cover;  
  background-position: center;
  font-family: Lato;
  color: white;
}


html {
height: 100%
}

Can someone help me fix the issue, that the img should go full screen on any screen size?

zenubeh
  • 67
  • 1
  • 1
  • 9

6 Answers6

1

Add following style to your code to avoid repeating the image:

background-repeat:no-repeat;
Charu Maheshwari
  • 1,583
  • 1
  • 8
  • 9
0

Since you applied it as background you can use this property to avoid double occurrence in higher resolution

background-repeat: no-repeat;

even you can mention all it in a single line like

background: #fff url('pic.jpg') no-repeat center center;

and if you want to stretch the image, then

background-size: 100% auto;
Aravind S
  • 2,347
  • 2
  • 12
  • 21
0
body {
  background: url(pic.jpg); 
  background-size: cover;  
  background-position: center;
  font-family: Lato;
  color: white;
  width:100%;
  height:100%;
}

html {
  height: 100%;
}
Jérémie Bertrand
  • 3,025
  • 3
  • 44
  • 53
midnightgamer
  • 444
  • 1
  • 5
  • 18
0

use

background-repeat:no-repeat;

and you can reduce code by using

background: url('pic.jpg') no-repeat cover center;
Suraj Libi
  • 515
  • 2
  • 9
0

body {
  background-repeat: no-repeat;
  width:100%;
  height:100%;
}
0

This could solve your problem:

body {
    width: 100%;
    height: 100vh;
    margin: 0;
    padding: 0;
    background-image: url('PATH_TO_IMG');
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
}

You can see an example here https://codepen.io/Nacorga/pen/mjmBLp

Nacorga
  • 507
  • 4
  • 17