Empty div vs div with text having inline-block property

后端 未结 4 1112
情书的邮戳
情书的邮戳 2021-02-20 07:49

Want to know the reason for this behavior.

CSS

div {
   display: inline-block;
   margin-right: 2px;
   width: 20px;
   background-color         


        
4条回答
  •  [愿得一人]
    2021-02-20 08:09

    Basically it got to do with the way that vertical-align: is calculated. So if you put vertical-aling:bottom; attribute in the css then you will notice it will be the same with and without text.

    you can read the this for more details.

    When the div has no content, padding is not drawn in the box (i.e. when when 0, if there is content, the browser calculates where the padding would be). so there is a little difference in calculating with and without text.

    Hope this is helpfull.

提交回复
热议问题