Skip to content

Instantly share code, notes, and snippets.

@CongAn
Created April 27, 2022 10:17
Show Gist options
  • Save CongAn/d100c9cf70c7d34b979ac154721563f3 to your computer and use it in GitHub Desktop.
Save CongAn/d100c9cf70c7d34b979ac154721563f3 to your computer and use it in GitHub Desktop.
/**
* 垂直水平居中
* 可增加 flex-direction: column; 让div保持块级元素
*/
div {
display: flex;
justify-content: center;
align-items: center;
}
/**
* 两端对齐并垂直居中
*/
div {
display: flex;
align-items: center;
justify-content: space-between;
}
/******** 绝对定位方案(陈旧) ********/
/**
* 垂直水平居中
*/
div {
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
}
/**
* 水平居中在底部
*/
div {
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment