Remove white space below image
You're seeing the space for descenders (the bits that hang off the bottom of 'y' and 'p') because img
is an inline element by default. This removes the gap:
.youtube-thumb img { display: block; }
Image inside div has extra space below the image
By default, an image is rendered inline, like a letter so it sits on the same line that a, b, c and d sit on.
There is space below that line for the descenders you find on letters like g, j, p and q.
You can:
- adjust the
vertical-align
of the image to position it elsewhere (e.g. themiddle
) or - change the
display
so it isn't inline.
div { border: solid black 1px; margin-bottom: 10px;}
#align-middle img { vertical-align: middle;}
#align-base img { vertical-align: bottom;}
#display img { display: block;}
<div id="default"><h1>Default</h1> The quick brown fox jumps over the lazy dog <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/f2/VangoghStarry-night2.jpg/300px-VangoghStarry-night2.jpg" alt="Sample Image"></div>
<div id="align-middle"><h1>vertical-align: middle</h1> The quick brown fox jumps over the lazy dog <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/f2/VangoghStarry-night2.jpg/300px-VangoghStarry-night2.jpg" alt="Sample Image"> </div> <div id="align-base"><h1>vertical-align: bottom</h1> The quick brown fox jumps over the lazy dog <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/f2/VangoghStarry-night2.jpg/300px-VangoghStarry-night2.jpg" alt="Sample Image"> </div>
<div id="display"><h1>display: block</h1> The quick brown fox jumps over the lazy dog <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/f2/VangoghStarry-night2.jpg/300px-VangoghStarry-night2.jpg" alt="Sample Image"></div>
How to get rid of white space below image with absolute positioned overlay div
By default, an image is rendered inline, like a letter.
You can adjust the vertical-align of the image to position it elsewhere (e.g. the middle) or change the display so it isn't inline.
White space under image
Add this
div{
line-height: 0;
}
Fiddle
Related Topics
Elements in a Flex Container Are Not Wrapping
How to Apply Mix-Blend-Mode While Keeping Text Opaque
Make Grid Items Fill Columns Not Rows
Edit Line Thickness of CSS 'Underline' Attribute
Stop Floating Divs from Wrapping
Flipping/Inverting/Mirroring Text Using CSS Only
Responsive Square Divs Cross Browser Compatible
Indent Starting from The Second Line of a Paragraph with CSS
Vertically Center Text in a 100% Height Div
Is This Empty Space Actually Margin-Right Which Is Not Recognized by Dev Tools
How to Add an Offsetted Outline to a CSS Shape
CSS Override Rules and Specificity
Pseudo Element Not Full Container Width When Border Used
Wget Recognizes Some Part of My Url Address as a Syntax Error