space between an inline-block element and a block element

前端 未结 2 1556
独厮守ぢ
独厮守ぢ 2021-01-26 10:33

What is that space between these two divs? I even removed the white space in html.

相关标签:
2条回答
  • 2021-01-26 10:43

    Where that space is coming from?

    From the inline-block element being aligned to the baseline of the “line” it is displayed on.

    Add vertical-align:bottom (or text-bottom, or middle, ortop, …) to it, and the space will be gone: http://jsfiddle.net/9thpuvwa/2/

    0 讨论(0)
  • 2021-01-26 10:58

    This appears to be caused by the vertical alignment. Where it's set to inline-block, by default the vertical alignment is set to baseline, which is slightly higher raised (probably to account for characters like 'y' and 'g' which dip below the line).

    vertical-align of top seems to fix it:

    #asd {
      ...
      vertical-align: top;
    }
    

    JSFiddle demo.

    0 讨论(0)
提交回复
热议问题