We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.element { width: 100px; height: 100px; position: absolute; left: 50%; top: 50%; // 高度一半 margin-top: -50px; // 宽度一半 margin-left: -50px; }
.element { width: 100px; height: 100px; position: absolute; left: 50%; top: 50%; // 50% 为自身尺寸一半 transform: translate(-50%. -50%); }
.element { width: 100px; height: 100px; position: absolute; left: 50%; top: 50%; right: 0; bottom: 0; margin: auto; }
<div class="container"> <div class="box">一些元素</div> </div>
.container { display: flex; justify-content: center; align-items: center; }
父级元素设置text-aligin: center;即可
text-aligin: center;
.container { display: grid; grid-template-columns: 50px; justify-content: center; }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
固定宽高、绝对定位元素
缺点
固定宽高、绝对定位元素
margin: auto
注意
Flex
行内元素
父级元素设置
text-aligin: center;
即可Grid
The text was updated successfully, but these errors were encountered: