The image inside the div has extra space below the image
P粉523335026
P粉523335026 2023-08-29 12:46:39
0
2
484
<p>Why is the height of <code>div</code> in the following code greater than the height of <code>img</code>? There is a gap below the image, but it doesn't seem to be padding/margin. </p> <p><strong>What is the gap or extra space below the image? </strong></p> <p><br /></p> <pre class="brush:css;toolbar:false;">#wrapper { border: 1px solid red; width:200px; } img { width:200px; }</pre> <pre class="brush:html;toolbar:false;"><div id="wrapper"> <img src="http://i.imgur.com/RECDV24.jpg" /> </div></pre> <p><br /></p>
P粉523335026
P粉523335026

reply all(2)
P粉909476457

Another option suggested in this Blog post is styling the image to style="display: block;"

P粉222320176

By default, the image is rendered inline, just like the letters, so it's on the same line as a, b, c, and d.

There is a space below this line for the letters g, j, p and q.

you can:

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="">
</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=""> </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=""> </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="">
</div>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!