css - 在 Bootstrap 4 input-group-prepend 中对齐中心

标签 css twitter-bootstrap bootstrap-4

我想要一个固定宽度的input-group-prepend,它比其中的内容大,但我希望内容水平居中。

我试过 text-centeralign-items-center,但它似乎总是左对齐。

如何让内容位于 input-group-text 的中间?

.input-group-text {
 min-width: 60px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="form-group">
  <div class="input-group">
    <div class="input-group-prepend">
      <div class="input-group-text">$</div>
    </div>
    <input type="text" class="form-control" id="inlineFormInputGroup" placeholder="Value">
  </div>
</div>

最佳答案

您需要 justify-content-center ( https://getbootstrap.com/docs/4.2/utilities/flex/#justify-content ) 因为 input-group-text 被定义为具有行方向的 flexbox 容器

.input-group-text {
 min-width: 60px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="form-group">
  <div class="input-group">
    <div class="input-group-prepend">
      <div class="input-group-text justify-content-center">$</div>
    </div>
    <input type="text" class="form-control" id="inlineFormInputGroup" placeholder="Value">
  </div>
</div>

关于css - 在 Bootstrap 4 input-group-prepend 中对齐中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54363713/

相关文章:

asp.net - CSS 相对大小的页眉/页脚

jquery - Datepicker 覆盖模式中的输入字段

javascript - 当我将目标保存为 PDF 时,window.print() 不显示更多设置

javascript - 通过 JS 设置时 Bootstrap 输入验证消息不显示 php

html - 如何在不冲突的情况下将两个 div 对齐?

html - 输入:hover and input:active for a textfield?有什么区别

html - Bootstrap 4 列内的固定顶部导航栏

html - 删除标签后背景图像保留

css - 如何在没有装订线的情况下在 Bootstrap 3 中创建 8 个偶数列

javascript - 光标 :move 时 firefox 表单不工作