Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there padding at the bottom of my image?

Tags:

html

css

I am using this CSS/HTML combo to emulate a two column layout:

HTML

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <div class="two-cols">
    <div class="left-col">
        <img src="http://stott.customer.netspace.net.au/images/aurora2.jpg" alt="Image"/>
    </div>
    <div class="right-col">
        Text
    </div>
</div>
</body>
</html>

CSS

.two-cols {
    border: 1px solid black;
    display: table;
    width: 100%;
}

.left-col, .right-col {
    display: table-cell;
    width: 50%;
}

img {
    width: 300px;
    height: 200px;
    padding: 0;
    margin: 0;
}

JSBin here.

But there's an unwanted padding at the bottom of my image:

Result

Any ideas why am I getting that and how can I get rid of that?

like image 632
TheFooProgrammer Avatar asked Dec 27 '12 11:12

TheFooProgrammer


People also ask

How do I get rid of the gap under my image?

In order to get rid of additional white space, there are 3 properties that can be used: Using the display property. Using vertical-align property. Using line-height property.

Why is there extra space at the bottom of my div?

If you try to put an image inside a <div> element that has borders, you will see an extra white space (around 3px) at the bottom of image. It happens because image is an inline-level element so browser adds some whitespace under the baseline to adjust other inline elements.

What is padding-bottom in IOS?

The padding-bottom property is used to specify the width of the bottom area of the element's padding box. That is, it specifies the area of space required at the bottom of the element's content, inside any defined border. Every element on a web page is rectangular.

What is the use of padding-bottom?

The padding-bottom CSS property sets the height of the padding area on the bottom of an element.


1 Answers

The default vertical-align is baseline that is applied to img as well. Make it bottom and it works:

img {
    vertical-align: bottom;
}
like image 50
Gumbo Avatar answered Oct 05 '22 08:10

Gumbo