Reputation:
i have this responzive grid and I dont know hot to remove space between top and bottom of div. How to fill with image whole div? You can see it here https://jsfiddle.net/jo3jorch/1/
<div>
<img src="http://beyondeurope.net/wp-content/uploads/2014/08/Top_10_Universities_in_New_York_City.jpg">
</div>
div {
width: 50%;
float: left;
}
div img {
width: 100%;
}
Upvotes: 0
Views: 9166
Reputation: 383
If regardless of the page width you're only having issues with the top and bottom of the image leaving space, you need height 100% rather than width:
HTML:
<div id="newyork">
<img src="http://beyondeurope.net/wp-content/uploads/2014/08/Top_10_Universities_in_New_York_City.jpg" />
</div>
CSS:
#newyork {
width: 300px;
height: 300px;
background: red;
}
#newyork img {
height: 100%;
width: auto;
}
https://jsfiddle.net/jo3jorch/8/
But if the space can sometimes appear top and bottom, there is a good answer to responsive image resizing here: Make image fill div completely without stretching
Upvotes: 1
Reputation: 2724
Here you go
https://jsfiddle.net/b7nxzt8m/1/
this was missing
img {
display:block;
}
Upvotes: 4
Reputation: 144
You want to add "display: block" to "div img". Images are actually textual elements, and therefore get the text gutter for the low-hanging bottoms of "g" and "j" and stuff.
Upvotes: 0