1. 使用 `margin: 0 auto;`:
```css
.button {
display: block;
margin-left: auto;
margin-right: auto;
width: 100px; /* 设置一个合适的宽度值 */
}
2. 使用 Flexbox:
```css
.parent {
display: flex;
justify-content: center;
align-items: center;
height: 100vh; /* 设置父容器高度为视口高度 */
}
.button {
/* 按钮样式 */
}
3. 使用 Grid 布局:
```css
.parent {
display: grid;
place-items: center;
height: 100vh; /* 设置父容器高度为视口高度 */
}
.button {
/* 按钮样式 */
}
4. 使用绝对定位和 transform:
```css
.parent {
position: relative;
height: 100vh; /* 设置父容器高度为视口高度 */
}
.button {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
请根据您的布局需求选择合适的方法。