Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IMG has 5px extra padding at bottom of div

Tags:

css

I have a div that has a mystery 5px bottom padding added to an image contained within it. I've tried resetting CSS padding and margin for all elements but to no avail. What am I missing?:

JSFIDDLE: http://jsfiddle.net/vbFx9/

HTML:

<div id="list">     <div id="boxscroll">         <div class="list-result">             <img src="images/ps-result.png">         </div>         <div class="list-result">             <img src="images/ps-result.png">         </div>         <div class="list-result">             <img src="images/ps-result.png">         </div>     </div> </div> 

CSS:

.list-result {     padding:0;     margin:0;     width:100%;     border-bottom: 1px #000 solid;     background:#f9f9f9; } .list-result:hover {     background:#e9e9e9; } #list {     top: 100px;     bottom:40px;     right: 20px;     position: absolute;     width: 20%;     max-width:300px; } #boxscroll {     font-family:'Open Sans';     background:#f9f9f9;     overflow: auto;     max-height:100%;     border: 8px solid #fff; } 
like image 561
alias51 Avatar asked Jul 21 '13 10:07

alias51


People also ask

Why is div bigger than IMG?

The gap or extra space under the image isn't a bug or issue, it is the default behaviour. The root cause is that images are replaced elements (see MDN replaced elements). This allows them to "act like image" and have their own intrinsic dimensions, aspect ratio....

Why is there padding in Div?

Padding is used to create space around an element's content, inside of any defined borders. This element has a padding of 70px.

How do you stop padding from increasing width?

to fix this, you simply need to update the box-sizing parameter and set this to border-box in your css. Or you can do this for all elements by simply adding the following. This tells the browser to account for any border and padding in the values you specify for an element's width and height.

How can the gap under the image be removed in CSS?

Display Property: The most commonly used solution is used to change the display property of the <img> tag inside the <div> container from default 'inline' value to 'block' using display : block property.

How much space does no padding give around an image?

No padding does not give any space around the image. It strictly sticks to the border. You can see it in the above 1 st image. Padding class has with padding 50px and 50px border.

How does image padding work in HTML or CSS?

How does Image Padding Work in HTML or CSS? Padding is always created space between innermost portions, whether it is image or content. Padding with image defines by img tag in CSS only. Syntax 1:

What is padding and margin in HTML?

An element's padding is the space between its content and its border. Note: Padding creates extra space within an element, while margin creates extra space around an element. This property can have from one to four values.

Does padding stick to the border of an image?

It strictly sticks to the border. You can see it in the above 1 st image. Padding class has with padding 50px 20px 50px and 5px border. Due to this padding around the image top 50px, left and right 20px and 50px bottom respectively.


2 Answers

use the following css: working jsFiddle

img{display:block;} 

Images are by default displayed inline - which causes the padding below the image. (because of line-height)

like image 165
Yotam Omer Avatar answered Sep 27 '22 18:09

Yotam Omer


Answered here. Use

.list-result {       line-height: 0; } 

Fiddle

like image 32
user764754 Avatar answered Sep 27 '22 20:09

user764754