Allen Yu Allen Yu
Home
  • 前端文章

    • JavaScript
  • 学习笔记

    • 《TypeScript入门教程》
GitHub (opens new window)
Home
  • 前端文章

    • JavaScript
  • 学习笔记

    • 《TypeScript入门教程》
GitHub (opens new window)
  • CSS

    • 使组件或者 div 居中的 4 个方法
      • 使组件或者 div 居中的 4 个方法
  • 学习笔记

  • ESLint

  • 前端
  • CSS
2022-03-23
目录

使组件或者 div 居中的 4 个方法

# 使组件或者 div 居中的 4 个方法

  • Flexbox
  • Margin auto a flex item
  • Grid
  • Position
/* Flexbox */
.parent {
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Margin auto a flex item */
.parent {
  display: flex;
}

.child {
  margin: auto;
}

/* Grid */
.parent {
  display: grid;
  justify-content: center;
  align-content: center;
}

/* use position */
.parent {
  position: relative;
}

.child {
  position: absolute;
  top: 100%;
  left: 100%;
  transform: translate(-50%, -50%);
}

Last Updated: 3/23/2022, 2:20:17 PM
《TypeScript 入门教程》

《TypeScript 入门教程》→

最近更新
01
4 月第 2 周总结
04-17
02
工具类型
04-01
03
Google 搜索小技巧
03-28
更多文章>
Theme by Vdoing | Copyright © 2018-2022 Allen Yu
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式