Created
April 27, 2022 10:17
-
-
Save CongAn/d100c9cf70c7d34b979ac154721563f3 to your computer and use it in GitHub Desktop.
CSS 弹性盒子布局:https://developer.mozilla.org/zh-CN/docs/Web/CSS/CSS_Flexible_Box_Layout 设置垂直位置:https://developer.mozilla.org/zh-CN/docs/Web/CSS/align-items 设置水平位置:https://developer.mozilla.org/zh-CN/docs/Web/CSS/justify-content
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 垂直水平居中 | |
* 可增加 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