What is the difference between display: inline and display: inline-block?

前端 未结 5 1969
孤城傲影
孤城傲影 2020-11-21 23:54

What exactly is the difference between the inline and inline-block values of CSS display?

5条回答
  •  忘掉有多难
    2020-11-22 00:20

    All answers above contribute important info on the original question. However, there is a generalization that seems wrong.

    It is possible to set width and height to at least one inline element (that I can think of) – the element.

    Both accepted answers here and on this duplicate state that this is not possible but this doesn’t seem like a valid general rule.

    Example:

    img {
      width: 200px;
      height: 200px;
      border: 1px solid red;
    }

    The img has display: inline, but its width and height were successfully set.

提交回复
热议问题