Reputation: 99
So I have an image which is 700px width which is what I'm using as a background image in a div which is 200px width.
I want to keep the image at that size so it can maintain a good resolution for smaller devices. However the issue I'm having is because the image is larger than the div the image overflows (hidden) but I want the image to resize and fit depending on the size of the div, instead of overflowing.
My div is currently:
.featurebox{
background: #F9C112 url(../img/pan1.jpg) no-repeat center top ;
width:200px
}
Upvotes: 0
Views: 8981
Reputation: 36
You can set background-size:
.featurebox {
background: #F9C112 url(https://upload.wikimedia.org/wikipedia/en/2/24/Lenna.png) no-repeat center top;
background-size: 200px 200px;
width: 200px;
height: 200px;
}
<div class="featurebox">
</div>
Upvotes: 0
Reputation: 617
Try adding this:
background-size: 100% 100%;
if you use
background-size: 100%;
the height is set to auto, and can then still overlap.
Upvotes: 2
Reputation: 5422
Define both width and height and then use background-size: cover
Upvotes: 3