Html 布尔玛:你如何将一个按钮放在一个盒子里?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42583298/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 14:28:27  来源:igfitidea点击:

Bulma: How do you center a button in a box?

htmlcssbulma

提问by Dazzle

<div class="box">
 <button class="button">Center me</button>
</div>

<button class="is-center">is not working.

<button class="is-center">不管用。

回答by Mohammad Usman

Yes, there is a native way.

是的,有一种本地方式。

Bulma offers has-text-centeredclass for centering text, inlineand inline-blockelements.

Bulma 提供has-text-centered用于居中文本inlineinline-block元素的类。

You can use following code:

您可以使用以下代码:

<div class="box has-text-centered">
  <button class="button">Center me</button>
</div>

Demo:

演示:

<link href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.3.2/css/bulma.css" rel="stylesheet"/>
<div class="box has-text-centered">
 <button class="button">Center me</button>
</div>

回答by Dazzle

Quickfix: wrap the button in a div with style="text-align:center;"

快速修复:用 style="text-align:center;" 将按钮包裹在一个 div 中

<div style="text-align: center;">
  <button class="button is-success">Center me</button>
</div>