布局方案汇总

水平布局

  • inline-block + text-align

    layout_1
  • table + margin

    layout_2
  • absoulte + transform

    layout_3
  • flex + justify-content/margin

    layout_4 layout_5

垂直居中

  • table-cell + vertical-align

    layout_6
  • absoulte + transform

    layout_7
  • flex + align-items

    layout_8

居中(水平垂直居中)

  • inline-block + text-align + table-cell + vertical-align

    layout_9
  • absoulte + transform

    layout_10
  • flex + justify-content + align-items

    layout_11

多列布局

定宽 + 自适应

  • float + margin

    layout_12
  • float + overflow

    layout_13
  • table

    layout_14
  • flex

    layout_15

多列定宽 + 自适应

  • 与定宽 + 自适应的布局方式一样,例如使用 float + overflow: layout_16

不定宽 + 自适应

不定宽的部分,宽带由内容来决定

  • float + overflow

    layout_17
  • table

    layout_18
  • flex

    layout_19

多列不定宽 + 自适应

与不定宽 + 自适应一样

等宽

  • float

    layout_20
  • table

    layout_21
  • flex

    layout_22

等高

  • table

    layout_23
  • flex

    layout_24
  • float

    layout_25