Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is there a small gap at the bottom of an `overflow: auto` box when overflowing?

I have the following demo setup. As you can see, for some reason, there is a small gap at the and I have no idea why it is there and how to get rid of it. Any explanation of what is going on would be appreciated.

#container {
  width: 100%;
  height: 200px;
  background: #ffaaaa;
  overflow: auto;
}

.content {
  background: #aaffaa;
  font-size: 8rem;
  line-height: 1;
}
<div id="container">
  <div class="content">CONTENT</div>
  <div class="content">CONTENT</div>
  <div class="content">CONTENT</div>
</div>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The text content is overflowing the line box. You can see this if you add some span with outline or border:

#container {
  width: full;
  height: 200px;
  background: #ffaaaa;
  overflow: auto;
}

.content {
  background: #aaffaa;
  font-size: 8rem;
  line-height: 1;
}
.content span {
  border: 1px solid;
}
<div id="container">
  <div class="content"><span>CONTENT</span></div>
  <div class="content"><span>CONTENT</span></div>
  <div class="content"><span>CONTENT</span></div>
</div>

You can clearly see how the border is overflowing. The reason is related to the line-height: 1 that set the height of the line box to something smaller than the text content

Don’t do it. You can control the height of a line box but not the height of the text content. Keep the default line-height or use a bigger value

#container {
  width: full;
  height: 200px;
  background: #ffaaaa;
  overflow: auto;
}

.content {
  background: #aaffaa;
  font-size: 8rem;
  /*line-height: 1;*/
}
.content span {
  border: 1px solid;
}
<div id="container">
  <div class="content"><span>CONTENT</span></div>
  <div class="content"><span>CONTENT</span></div>
  <div class="content"><span>CONTENT</span></div>
</div>

Related: Can specific text character change the line height?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading