html - 如何在列中制作两个按钮?

标签 html css button

如何在一列和中心制作两个按钮? 我尝试使用 flexbox,但是当我添加 flex-direction:column 时,它会使按钮的宽度变为 100% 我需要这样 enter image description here

HTML

<form>
  <button type="button">Regulamin</button>
  <button type="button">Formularz kontaktowy</button>
</form>

CSS

form {
    display: flex;
    justify-content: center;
    flex-direction: column;
    padding-top: 20px;
}

最佳答案

实现此目的的一种方法是为按钮指定 width 并通过 margin: 0 auto 将其居中。

form button {
    width: 100px;
    margin: 0 auto;
}

要使用的示例片段:

form {
  display: flex;
  justify-content: center;
  flex-direction: column;
  padding-top: 20px;
}
form button {
  width: 100px;
  margin: 0 auto;
}
<form>
  <button type="button">Regulamin</button>
  <button type="button">Formularz kontaktowy</button>
</form>

关于html - 如何在列中制作两个按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40328578/

相关文章:

html - 如何将图像放入 100% 高度的表格中?

javascript - 单击显示图像时

html - CSS:在任何移动屏幕中将导航居中

html - 无法在按钮内移动文本

button - 如何使用我自己的自定义按钮并使用 wxpython 进行设计

html - 根据浏览器更改 DIV 的属性

javascript - 使用 Javascript 突出显示 HTML 中的文本后,如何获取包含 HTML 元素的字符串?

html - 褪色图库

html - 标题中的每个词在他们自己的行 HTML/CSS

javascript - 为 Ext.Net 按钮动态设置工具提示