Reputation:
Why the background image not working with
HTML
<div class="container" style="background-color: red;"></div>
CSS
.container {
width: 100%;
height: 385px;
background-image: url(http://fc08.deviantart.net/fs71/i/2013/082/a/c/png_grass_by_moonglowlilly-d5z1o5t.png);
background-position: center top;
background-size: 100% auto;
background-size: cover;
border-bottom: 1px solid #3f4858;
background-repeat: repeat-x;
left: 0px;
top: 0px;
}
Upvotes: 0
Views: 137
Reputation: 58
The image is of size 1024x819px and the grass is starting from 232px
from top so you need to position your background image or change your div.container size so as to fit the image within the given size.
Demo-1 with container size changed:
Demo-2 with image position changed with your code snippet only.:
just notice background-position I have changed to 0px -232px;
Upvotes: 1
Reputation: 1456
Try This:
.container{
width:300px;
height:385px;
background-image:url('http://fc08.deviantart.net/fs71/i/2013/082/a/c/png_grass_by_moonglowlilly-d5z1o5t.png');
background-position: center top;
background-size: 100% auto;
background-size:cover;
border-bottom:1px solid #3f4858;
background-repeat:repeat-x;
left:0px;
top:0px;
}
<div class="container" style="background-color:red;">
Upvotes: 1
Reputation: 38252
Apart from the already mentioned spelling error
The problem here is with the size of your container and the size of your background image. Your image has a lot of space on top and you will see nothing for the size of you container. Check if you change the background-size
property to:
background-size: 100% 100%;
For the porperty background-size you can also use contain
:
the background image should be scaled to be as large as possible while ensuring both its dimensions are less than or equal to the corresponding dimensions of the background positioning area
Upvotes: 3
Reputation: 7597
Your width: 100%
depends on width of parent element. And its not set. Thats why. So change your CSS to this:
.container{
width:300px;
height:385px;
background-image:url(http://fc08.deviantart.net/fs71/i/2013/082/a/c/png_grass_by_moonglowlilly-d5z1o5t.png);
background-position: center top;
background-size: 100% auto;
background-size:cover;
border-bottom:1px solid #3f4858;
background-repeat:repeat-x;
left:0px;
top:0px;
}
Also why you have in your HTML style="background-color:red;"
? Do you want to have as background image png_grass_by_moonglowlilly-d5z1o5t.png
or red color? Or you want to have in transparency of that PNG image red color?
Upvotes: 0