Why does image use display: inline but behaves like an inline-block element

前端 未结 6 762
醉话见心
醉话见心 2021-01-06 01:02

Why is the default display style for image inline instead of inline-block?

Is there any difference between inline and inline-block for img elements, from what I can

6条回答
  •  抹茶落季
    2021-01-06 01:22

    The first part of your question is already answered, so I shall not repeat.

    For the second part, some browsers like Firefox renders a no-image img tag as a span even when width and height attributes are specified in CSS.

    You can try it out yourself with this HTML code:

    no image
    no image

    And corresponding CSS:

    img {
        height: 100px;
        width: 100px;
        background: cyan;
    }
    #iblock {
        display: inline-block;
    }
    

    Or see the difference in rendering effect with this Demo on JsFiddle.

提交回复
热议问题