How to calculate the height of an inline element

前端 未结 5 1994
無奈伤痛
無奈伤痛 2020-11-30 10:18

I have a span element with the following CSS:

span.test {
  font-size: 20px;
  line-height: 1;
}

Why the calculated height of

5条回答
  •  粉色の甜心
    2020-11-30 11:02

    I couldn't find an answer to why it is applied. I found many forums with the same question...

    But, as an answer to your request:

    Is it possible to make it tall 20px without using inline-block ?

    I managed to do it only by floating the element. It seems to lose whatever it was that was padding it... Then, setting the line-height to specific 20px makes it work.

    span.test {
      font-size: 20px;
      line-height: 20px;
      float: left;
    }
    A

    EDIT

    Actually, adding float works because it makes inline elements behave like block elements.

    See: https://developer.mozilla.org/en-US/docs/Web/CSS/float

提交回复
热议问题