html - 我怎样才能让这个 <div> 居中?

标签 html css

这是正在发生的事情:http://prntscr.com/g67d7p

enter image description here

如您所见,“支付框”没有正确居中。我尝试了多种方法来解决这个问题,但都失败了。

CSS:

div[id=rollover-button]{
    height: 100px;
    width: 160px;
    background-color: #E4ECF1;
    text-align: center;
    line-height: 100px;
    font-size: 40px;
    color: gray;
    font-weight: 300;
    display: inline-block;
    float: left;
}

div[id=payout-button]{
    height: 100px;
    width: 160px;
    background-color: #E4ECF1;
    text-align: center;
    line-height: 100px;
    font-size: 40px;
    color: gray;
    font-weight: 300;
    display: inline-block;
}

div[id=chance-button]{
    height: 100px;
    width: 160px;
    background-color: #E4ECF1;
    text-align: center;
    line-height: 100px;
    font-size: 40px;
    color: gray;
    font-weight: 300;
    display: inline-block;
    float: right;
}

HTML:

<div id="buttons">
            <div id="rollover-button">
                >50.00
            </div>
            <div id="payout-button">
                2.0000x
            </div>
            <div id="chance-button">
                50%
            </div>
        </div>

如何解决这个问题,使支付框完美居中?

最佳答案

您可以使用 flex 属性。我已经从元素中删除了所有 floatsdisplay 属性,并在父级上使用了 flex。希望这对你有帮助。

#buttons {
  display: flex;
  justify-content: space-between;
}

div[id=rollover-button] {
  height: 100px;
  width: 160px;
  background-color: #E4ECF1;
  text-align: center;
  line-height: 100px;
  font-size: 40px;
  color: gray;
  font-weight: 300;
}

div[id=payout-button] {
  height: 100px;
  width: 160px;
  background-color: #E4ECF1;
  text-align: center;
  line-height: 100px;
  font-size: 40px;
  color: gray;
  font-weight: 300;
}

div[id=chance-button] {
  height: 100px;
  width: 160px;
  background-color: #E4ECF1;
  text-align: center;
  line-height: 100px;
  font-size: 40px;
  color: gray;
  font-weight: 300;
}
<div id="buttons">
  <div id="rollover-button">
    >50.00
  </div>
  <div id="payout-button">
    2.0000x
  </div>
  <div id="chance-button">
    50%
  </div>
</div>

关于html - 我怎样才能让这个 <div> 居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45583500/

相关文章:

javascript - 自定义文本布局 CSS-JS

jquery - 需要使用 twitter bootstrap 创建动态磁贴

html - 如何仅模糊背景而不模糊其下面的 div?

html - 是否可以调用另一个定义了 SVG 的 HTML 文档,并将其用作另一个 HTML 文档中的 SVG?

html - 在 Firefox 上提供与 Safari 相同的宽度

html - 中间元件流体高度

javascript - 单击时显示 div

javascript - 微调 megamenu 的 jQuery 要求

javascript - 为html中的元素制作边框 block

html - 具有适当滚动行为的绝对定位的布局行为