inline 与inline-block到底有什么区别

之前对inline与inline-block一直感觉比较容易混淆他们之间的特性,特别是在看到这个图的时候,这是对“box2”设置为{display:inline-block;}

那么什么是inline呢,根据字面意思,它是在一条线上的,那么内联就是这些元素是排成一条线的;

那inline-block又是什么呢,在W3SCHOOL里面解释它就是排成线,但表现得像块一样,不过感觉还是很模糊;

直到看到这样一个解答:


Inline elements:

  1. respect left & right margins and padding, but not top & bottom
  2. cannot have a width and height set
  3. allow other elements to sit to their left and right.

Block elements:

  1. respect all of those
  2. force a line break after the block element

Inline-block elements:

  1. allow other elements to sit to their left and right
  2. respect top & bottom margins and padding
  3. respect height and width

从画面看的话如下图:

图片地址





猜你喜欢

转载自blog.csdn.net/qill_qill/article/details/46354641