主要介绍元素垂直的一些技巧,水平同理

1、vertical-align: middle;

前提:父元素display: table-cell; vertical-align: middle;
元素居中处理

2、align-items: center;

前提:父元素display: flex; align-items: center;
元素居中处理

3、align-self: center;

前提:父元素display: flex; 子元素align-self: center;
元素居中处理

4、transform: translateY(-50%)

前提:子元素存在定位,top: 50%; transform: translateY: (-50%);
元素居中处理

5、margin: auto;

前提:子元素相对父元素绝对定位position: absolute; top; 0; bottom: 0; margin: auto;
元素居中处理

6、line-height: xxx;

前提:子元素为单行文本, line-height: xxx; (xxx为父容器height大小)
元素居中处理

相关文章:

  • 2021-12-04
  • 2022-01-27
  • 2022-12-23
  • 2022-12-23
  • 2021-05-28
  • 2022-12-23
  • 2019-09-29
猜你喜欢
  • 2021-06-27
  • 2021-12-19
  • 2021-09-30
  • 2022-12-23
  • 2021-12-17
  • 2021-09-30
  • 2021-04-15
相关资源
相似解决方案