0

I want a image to fill the browsers and these are html side code

<!DOCTYPE html>
<html>
<head>
    <title>Testing</title>
    <link rel="stylesheet" type="text/css" href="css/styles.css">
</head>
<body>

</body>
</html>

since I want the image to be occupied fully in screen i declared it inside the body in css like this but sadly image is not appearing in the screen

body{
    background-image:url('../img/bgmapsimage.png');
    background-repeat:no-repeat;
    background-size:contain;
    background-position:center;
}

yes the image name is correct and location is correct as well.This is the link i refered link

Community
  • 1
  • 1
Gladwin James
  • 563
  • 3
  • 10
  • 22

5 Answers5

0

Check out this link: https://css-tricks.com/perfect-full-page-background-image/

body{ 
    background: url(images/bg.jpg) no-repeat center center fixed; 
   -webkit-background-size: cover;
   -moz-background-size: cover;
   -o-background-size: cover;
    background-size: cover;
}

You can also use vh to have full height image no matter the screen size.

felix91
  • 452
  • 3
  • 11
0

To test your CSS, try to change the URL in this line

background-image:url('../img/bgmapsimage.png');

to an absolute URL of which you know it will work, like

background-image:url('http://placehold.it/400x300');

If this image is shown, your original image path is the problem (the folder structure which your HTML, CSS and image files are in). If it's not shown, most likely your CSS code itself is the reason.

Johannes
  • 64,305
  • 18
  • 73
  • 130
0

Your body element is empty and therefore has no height. if you add a minimum height, you'll see the image:

body{
    background-image:url('../img/bgmapsimage.png');
    background-repeat:no-repeat;
    background-size:contain;
    background-position:center;
    min-height: 200px;
}
Javier Rey
  • 1,539
  • 17
  • 27
0

Update your CSS as like below

body{ 
    background: url('../img/bgmapsimage.png') no-repeat center center fixed; 
    -webkit-background-size: center;
    -moz-background-size: center;
    -o-background-size: center;
    background-size: center;
}

OR

body{ 
    background: url('../img/bgmapsimage.png') no-repeat center center fixed; 
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
}

You can also add css for html tag

Example

html{
 /*Your CSS*/
}

Here is some CSS tricks for full screen background image CSS Tricks

Sumon Sarker
  • 2,707
  • 1
  • 23
  • 36
0
body{
    //backround image and all
    background-size: cover;
}

Though it depends on the size of the image you are working with.