0

I have a <div> that includes a background image like this:

<div style="
  background: url('file://D:/DwyaneJohnsonBaller.jpg');
  width:100%; 
  height:1200px; 
  background-size: 100%;">
</div>

I've also tried to make the style of the <div/> in CSS format.

The problem I'm facing is that when I display the HTML file, I find some white spacing from top, right, left and bottom (i.e not fit with the whole web page).

Alois Mahdal
  • 10,763
  • 7
  • 51
  • 69
  • possible duplicate of [CSS background image to fit width, height should auto-scale in proportion](http://stackoverflow.com/questions/9262861/css-background-image-to-fit-width-height-should-auto-scale-in-proportion) – connexo Aug 03 '15 at 13:48
  • when width:100%, height should not be set in px. That is what creates the white space. – Blix Aug 03 '15 at 13:51

5 Answers5

2

To make backgound cover all of element, you should specify background-size as cover.

Previously on Stack Overflow: https://stackoverflow.com/a/9265035/211131

Community
  • 1
  • 1
Kaspars Foigts
  • 159
  • 1
  • 4
2

I sounds as though you need to remove the default margin from the body

body {
    margin: 0;
}

Try looking into "CSS Reset". There are several, just google that term.

Paulie_D
  • 107,962
  • 13
  • 142
  • 161
2

Use - margin: 0;

You can solve this by adding the following code to the head part of your html file:

<style>
  body{
  margin:0;
  }
</style>

Without this browser will display the content with blank spaces on all sides.

Ronald P Mathews
  • 2,178
  • 1
  • 22
  • 26
0

in your CSS file, you can input the following lines of code to make sure you get the right image, and also you can modify the size of the image to remove the white lines you are experiencing

body 
{
  background-image:url("otherimages/background.jpg");
  background-size:105%;
} 

Also, since "background-size" is there, you don't need to have "width and height" parameters. You can experiment with this, to make sure it works with your own project

Kebab Programmer
  • 1,213
  • 2
  • 21
  • 36
0
body{
 margin: 0;
 padding: 0;
}
Andy
  • 49,085
  • 60
  • 166
  • 233