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

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

    splattne's answer probably covered most of everything so I won't repeat the same thing, but: inline and inline-block behave differently with the direction CSS property.

    Within the next snippet you see one two (in order) is rendered, like it does in LTR layouts. I suspect the browser here auto-detected the English part as LTR text and rendered it from left to right.

    body {
      text-align: right;
      direction: rtl;
    }
    
    h2 {
      display: block; /* just being explicit */
    }
    
    span {
      display: inline;
    }

    هذا عنوان طويل one two

    However, if I go ahead and set display to inline-block, the browser appears to respect the direction property and render the elements from right to left in order, so that two one is rendered.

    body {
      text-align: right;
      direction: rtl;
    }
    
    h2 {
      display: block; /* just being explicit */
    }
    
    span {
      display: inline-block;
    }

    هذا عنوان طويل one two

    I don't know if there are any other quirks to this, I only found about this empirically on Chrome.

提交回复
热议问题