在HTML中:
在CSS中:
.parent {
display: flex; /*将父元素设置为弹性盒子*/
justify-content: center; /*将子元素水平居中*/
align-items: center; /*将子元素垂直居中*/
}
.child {
/*可选项:调整按钮样式*/
padding: 10px;
border: none;
background-color: blue;
color: #fff;
}
这样,按钮就可以在父元素中居中对齐了。
上一篇:按钮无法居中
下一篇:按钮无法居中在部分中央