gpt4 book ai didi

html - 我想水平对齐按钮并使用 css 将它们居中

转载 作者:行者123 更新时间:2023-11-28 02:04:50 28 4
gpt4 key购买 nike

我正在尝试使用 CSS 在页面中央顶部水平对齐 4 个按钮。这就是我的

button {
background-color: rgb(243, 243, 243);
border: 5px;
color: #000000;
padding: 15px 32px;
text-align: center;
margin: 4px 2px;
cursor: pointer;
-webkit-transition-duration: 0.6s;
transition-duration: 0.6s;
cursor: pointer;
display: block;
margin: auto;
}

每当我这样做时,按钮都会在中心对齐,但也会垂直对齐,它们应该是水平的。我已经试过了:

显示:内联 block ;代替显示: block ;

但随后我的按钮水平对齐但不在我的页面顶部居中。

最佳答案

最好的方法是在容器中使用 text alig,如下所示:

.container {
text-align: center;
}
 <div class='container'>
<button>MyBtn1</button>
<button>MyBtn1</button>
<button>MyBtn1</button>
</div>

关于html - 我想水平对齐按钮并使用 css 将它们居中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49085308/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com