首先,您好,感谢您抽出宝贵时间! 我有一个无法用 bootsrap 解决的问题,我试图将 2 个按钮置于 div 的中心,在此代码中,按钮左对齐,如何将它们居中? 这是我的代码:
<div class="align-self-center">
<button type="button" class="btn btn-outline-primary"> BTN1</button><button type="button" class="btn btn-success">BTN2</button>
</div>
最佳答案
使用 bootstrap 提供的文本中心类来对齐您的按钮。
<div class="text-center">
<button type="button" class="btn btn-outline-primary">BTN1</button>
<button type="button" class="btn btn-success">BTN2</button>
</div>
text-center 类基本上是在做 -
text-align:center;
附言不确定 .align-self-center 在这里做什么
建议 - 我看到您正在使用 bootstrap 4。如果满足您的要求,您也可以使用“btn-group”类。 Click here to go to bootstrap 4 docs
关于html - 在 bootstrap 的 div 中居中放置 2 个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51104945/