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

前端 未结 5 1964
孤城傲影
孤城傲影 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:33

    A visual answer

    Imagine a element inside a

    . If you give the element a height of 100px and a red border for example, it will look like this with

    display: inline

    display: inline

    display: inline-block

    display: inline-block

    display: block

    enter image description here

    Code: http://jsfiddle.net/Mta2b/

    Elements with display:inline-block are like display:inline elements, but they can have a width and a height. That means that you can use an inline-block element as a block while flowing it within text or other elements.

    Difference of supported styles as summary:

    • inline: only margin-left, margin-right, padding-left, padding-right
    • inline-block: margin, padding, height, width

提交回复
热议问题