When using inline-block, an empty inline div element within a hidden container curiously gains height. Why does this occur, in contrast to the behavior of display:block?
Display:inline-block imparts specific formatting on the element:
When the inline-block element is empty, it assumes its basic line-height, even though there's no font or text content. This results in the element gaining a small but noticeable height, despite its empty state.
A workaround to prevent this height issue is to use a wrapper with font-size:0 to eliminate the line-height calculation:
.wrapper { font-size: 0; } .wrapper div { font-size: medium; }
Update: Understanding Inline-Block Height
Contrary to initial assumptions, the exact height of an empty inline-block element is not officially documented. However, observations and testing suggest that:
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3