How to make a background image full size

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How to make a background image full size



I am trying to make a background image full size: that doesnt mean that it should cover all page, what I mean is that the image width should be full window size and the height should be auto(the image should rescale and be scrollable if needed). This is what i have tried:


body
width: 100%;
height: 100%;
background: url("../Images/BG_main.png")no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;



but it just covers the full window and cuts of the lower part of the image,
I have also tried this:


body
width: 100%;
height: auto;
background: url("../Images/BG_main.png")no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;



but then the background disappears if body is empty.
As I am new to HTML and css, I would really appreciate some help.



Thanks in advance!





for your reference: https://jsfiddle.net/ThinkingStiff/jUr9E/
– vishnu
10 mins ago





This is easily possible with <img> tag with width:100%. You have any technical issues in trying it?
– Pons Purushothaman
7 mins ago





Yes, i have achiaved this with img tag, but I want other elements to be on top. And I am not shoure if its right to put relative position on all other elements.
– boandriy
4 mins ago




2 Answers
2



You need to set height 100% to .body class to cover the full page. and remove center center fixed properties.


.body
width: 100%;
height: 100%;
background: url("../Images/BG_main.png")no-repeat;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;





Thanks for attempts, but it still cuts the lowwer part of the image.
– boandriy
7 mins ago



You should set the HTML to a height of 100% too, like this:




body, html height: 100%;
body
background: red url("../Images/BG_main.png") no-repeat center center fixed;
background-size: cover;



Too see what goes wrong, right-click and select 'inspect element'. Then try to find the HTML and the BODY element. Look for their heights and see if they equal the window height.



https://jsfiddle.net/n6ef81qj/





Thanks for attempts, but it still cuts the lowwer part of the image.
– boandriy
7 mins ago





Are you sure the dot before body needs to be there?
– JoostS
3 mins ago





Sorry, misswritten.
– boandriy
2 mins ago






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard