Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image will not fill div

Tags:

html

css

image

CSS/HTML problem.

This is crazy - I can only assume that I am an idiot. I cannot make my image fill the div it is in. There is consistently 5px "padding" beneath the image.

Here is the html:

<!doctype html>

<head><link rel="stylesheet" href="style.css" type="text/css" /></head>

<body>
<div class="row">
<img src="pic2.jpg" />
</div>
</body>

And here is the CSS:

body, .row, img {
padding: 0;
margin: 0;
border: none;
}

.row {
width: 80%;
background-color: orange;
}

img{
width: 50%;
}

This is the result:

http://imgur.com/yELMe

As you can see, the (stupid) blue and red image does not fill the orange div. There is a consistent 5px of orange showing beneath the image. This isn't affected by changes to the % widths of the div or the image, or by resizing the window.

I can fix this with "margin: -5px;", but I want to know why it is happening (especially if under different circumstances the amount is more or less than 5px).

Thanks for your help (and sorry again if this is a ridiculous error on my part).

like image 427
Joe_AK Avatar asked Apr 22 '12 09:04

Joe_AK


2 Answers

Add a vertical-align value (other than the default baseline) to your image like: top, middle...

vertical-align: top;
like image 134
Roko C. Buljan Avatar answered Nov 07 '22 14:11

Roko C. Buljan


I fixed this by setting display of img to block:

display: block;
like image 42
Sky Avatar answered Nov 07 '22 14:11

Sky