Empty div vs div with text having inline-block property

后端 未结 4 1203
情书的邮戳
情书的邮戳 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:06

    Hi please see here: http://jsfiddle.net/dd24z/ by default text is vertical-align to top but you can change that behavior;

    div {
        display: inline-block;
        margin-right: 2px;
        width: 20px;
        background-color: red;
        vertical-align: bottom;
    }
    

    http://www.w3.org/TR/2008/REC-CSS2-20080411/visudet.html#line-height

    'vertical-align': baseline Align the baseline of the box with the baseline of the parent box. If the box doesn't have a baseline, align the bottom of the box with the parent's baseline.

提交回复
热议问题