Why does overflow: hidden add additional height to an inline-block element?

uber5001

In this example...

HTML

<body>
  <div>
    <div>foo bar</div>
  </div>
</body>

CSS

body, html, div {
  height: 100%;
  margin: 0;
}
div div {
  display: inline-block;
  overflow: hidden;
}

Why does overflow: hidden cause a vertical scrollbar? Additionally, why is this height not attributed to anything on the page? It's like an invisible margin.

The 100% height of all the elements is intentional. In theory, that should cause the inner-most div to expand to meet the viewport. And it does! ...so long as overflow: hidden is not there, Why?

uber5001

The extra height is the same height as the height difference between vertical-align: baseline, and vertical-align: bottom. The "descender line". That's where the seemingly random "5 extra pixels" comes from. If the font size is 10 times as large, this gap will also be 10 times as large.

Also, it seems that when overflow: hidden is not there, the inline-block element has its baseline as the same baseline of its last line of text.

This leads me to believe that overflow: hidden forces the baseline of the entire inline-block element to be at the bottom of the element. Even though there is no text there, the parent of the inline-block element reserves space for the descender line. In the example given in the question, it cannot be easily seen since the parent of the inline-block element has height: 100%. So, instead, that extra space reserved for the descender line overflows out of that parent div.

Why is this space still there, even though there's no text? I think that's because the inline-block creates an inline formatting context, which is what causes this space. Were this element to be a block, it would only create this inline formatting context once it encounters an inline element or text.

This is just a theory, but it seems to explain it. It also explains why @Jonny Synthetic's answer works: adding overflow: hidden to the parent hides that extra descender line.

Thanks to @Hashem Qolami for the jsbins that gave me this theory.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

overflow:hidden on inline-block adds height to parent

From Dev

Why baseline of `inline-block` element with `overflow:hidden` is set to its bottom margin?

From Dev

Making a <span> element inline-block and overflow: hidden will displace him?

From Dev

Why "display: inline-block" add a 3px height space in the bottom of element?

From Dev

css overflow:hidden with display:inline-block

From Dev

Why does inline-block cause this div to have height?

From Dev

I want to understand the exact reason why overflow:hidden and display:inline-block is used here

From Dev

I want to understand the exact reason why overflow:hidden and display:inline-block is used here

From Dev

Why does these inline-block element produce extra width?

From Dev

Why does dev tool lists this inline element as block?

From Dev

Understanding the wrapping behavior of inline-block elements with overflow:hidden

From Dev

overflow:hidden + display:inline-block moves text upwards

From Dev

Extra space when using overflow:hidden in inline-block list

From Dev

inline-block vs. block: why does adding a "border" change inner height?

From Dev

Inline-block element height issue

From Dev

Why does overflow hidden affect height and how can I fix it in this example?

From Dev

Why doesn't the inline-block element occupy full height in the following example?

From Dev

Why does my element align itself to its sibling? aka overflow: hidden on Parent breaks left: 50% on Children

From Dev

Why does my element align itself to its sibling? aka overflow: hidden on Parent breaks left: 50% on Children

From Dev

CSS "table-cell" styled element: Maximum height (and overflow: hidden)

From Dev

Using text-overflow for an element with an inline-block

From Dev

Using text-overflow for an element with an inline-block

From Dev

why the overflow:hidden creates BFC(Block Formatting Context)?

From Dev

content overflow in display:inline-block; why and how?

From Dev

Why does applying `inline-block` force dimensions onto my span element?

From Dev

Why does inline-block work that way?

From Dev

CSS mystery white space above and below container when overflow: hidden is used on an inline-block

From Dev

Hide overflow of inline element

From Dev

Why isn't my inline-block span inheriting height?

Related Related

  1. 1

    overflow:hidden on inline-block adds height to parent

  2. 2

    Why baseline of `inline-block` element with `overflow:hidden` is set to its bottom margin?

  3. 3

    Making a <span> element inline-block and overflow: hidden will displace him?

  4. 4

    Why "display: inline-block" add a 3px height space in the bottom of element?

  5. 5

    css overflow:hidden with display:inline-block

  6. 6

    Why does inline-block cause this div to have height?

  7. 7

    I want to understand the exact reason why overflow:hidden and display:inline-block is used here

  8. 8

    I want to understand the exact reason why overflow:hidden and display:inline-block is used here

  9. 9

    Why does these inline-block element produce extra width?

  10. 10

    Why does dev tool lists this inline element as block?

  11. 11

    Understanding the wrapping behavior of inline-block elements with overflow:hidden

  12. 12

    overflow:hidden + display:inline-block moves text upwards

  13. 13

    Extra space when using overflow:hidden in inline-block list

  14. 14

    inline-block vs. block: why does adding a "border" change inner height?

  15. 15

    Inline-block element height issue

  16. 16

    Why does overflow hidden affect height and how can I fix it in this example?

  17. 17

    Why doesn't the inline-block element occupy full height in the following example?

  18. 18

    Why does my element align itself to its sibling? aka overflow: hidden on Parent breaks left: 50% on Children

  19. 19

    Why does my element align itself to its sibling? aka overflow: hidden on Parent breaks left: 50% on Children

  20. 20

    CSS "table-cell" styled element: Maximum height (and overflow: hidden)

  21. 21

    Using text-overflow for an element with an inline-block

  22. 22

    Using text-overflow for an element with an inline-block

  23. 23

    why the overflow:hidden creates BFC(Block Formatting Context)?

  24. 24

    content overflow in display:inline-block; why and how?

  25. 25

    Why does applying `inline-block` force dimensions onto my span element?

  26. 26

    Why does inline-block work that way?

  27. 27

    CSS mystery white space above and below container when overflow: hidden is used on an inline-block

  28. 28

    Hide overflow of inline element

  29. 29

    Why isn't my inline-block span inheriting height?

HotTag

Archive