租用问题

质量为本、客户为根、勇于拼搏、务实创新

< 返回租用问题列表

怎么让div垂直居中(23种方法总结),怎么让div垂直居中

发布时间:2023-09-28 05:07:20

怎样让div垂直居中(23种方法总结)

  1. 使用flexbox布局,在父元素上设置display: flex;和align-items: center;属性。
  2. 使用position和transform属性,将子元素的top和left设置为50%,然后使用transform: translate(⑸0%, ⑸0%);将子元素居中。
  3. 使用position和margin属性,将子元素的top和left设置为50%,然后使用margin-top和margin-left将子元素居中。
  4. 使用display: table;和display: table-cell;属性,将父元素设置为table,子元素设置为table-cell,并使用vertical-align: middle;将子元素垂直居中。
  5. 使用display: grid;和place-items: center;属性,将父元素设置为grid,并使用place-items: center;将子元素居中。
  6. 使用position属性,将父元素设置为relative,子元素设置为absolute,并使用top: 50%;left: 50%;transform: translate(⑸0%, ⑸0%);将子元素居中。
  7. 使用display: flex;和justify-content: center;属性,将父元素设置为flex,并使用justify-content: center;将子元素水平居中。
  8. 使用display: flex;和align-self: center;属性,将父元素设置为flex,并在子元素上使用align-self: center;将子元素垂直居中。
  9. 使用display: inline-block;和vertical-align: middle;属性,将父元素设置为inline-block,并使用vertical-align: middle;将子元素垂直居中。
  10. 使用display: flex;和margin: auto;属性,将父元素设置为flex,并使用margin: auto;将子元素居中。
  11. 使用display: table;和display: table-cell;属性,将父元素设置为table,子元素设置为table-cell,并使用text-align: center;将子元素水平居中,使用vertical-align: middle;将子元素垂直居中。
  12. 使用position属性,将父元素设置为relative,子元素设置为absolute,并使用top: 0;bottom: 0;left: 0;right: 0;margin: auto;将子元素居中。
  13. 使用display: flex;和align-content: center;属性,将父元素设置为flex,并使用align-content: center;将子元素垂直居中。
  14. 使用display: flex;和align-items: center;属性,将父元素设置为flex,并使用align-items: center;将子元素垂直居中。
  15. 使用display: flex;和justify-items: center;属性,将父元素设置为flex,并使用justify-items: center;将子元素水平居中。
  16. 使用display: flex;和place-content: center;属性,将父元素设置为flex,并使用place-content: center;将子元素居中。
  17. 使用display: flex;和place-items: center;属性,将父元素设置为flex,并使用place-items: center;将子元素居中。
  18. 使用display: flex;和align-self: center;属性,将父元素设置为flex,并在子元素上使用align-self: center;将子元素垂直居中。
  19. 使用display: flex;和justify-self: center;属性,将父元素设置为flex,并在子元素上使用justify-self: center;将子元素水平居中。
  20. 使用display: flex;和align-content: center;属性,将父元素设置为flex,并使用align-content: center;将子元素垂直居中。
  21. 使用display: flex;和place-content: center;属性,将父元素设置为flex,并使用place-content: center;将子元素居中。
  22. 使用display: flex;和place-self: center;属性,将父元素设置为flex,并在子元素上使用place-self: center;将子元素居中。
  23. 使用display: flex;和align-items: center;属性,将父元素设置为flex,并使用align-items: center;将子元素垂直居中。