html - 如何将按钮移动到左侧?

标签 html css bootstrap-4

我正在使用引导文档中的这个 modalExample

<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">Open modal</button>

<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">New message</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form>
          <div class="form-group">
            <label for="recipient-name" class="col-form-label">Recipient:</label>
            <input type="text" class="form-control" id="recipient-name">
          </div>
          <div class="form-group">
            <label for="message-text" class="col-form-label">Message:</label>
            <textarea class="form-control" id="message-text"></textarea>
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary">Send message</button>
      </div>
    </div>
  </div>
</div>

如何将“发送消息”按钮移到左侧而不是默认的右侧?

我在 class=""等处尝试了诸如 text-leftposition-left 之类的东西。对我来说没有任何作用

谢谢!

最佳答案

只需将 justify-content: flex-start !important 添加到 .modal-footer 即可。

由于 Bootstrap 使用 justify-content: flex-end 将按钮定位在页脚的左侧,因此上面的规则与 !important 一起可以覆盖原始 Bootstrap 的样式并将按钮移至左侧。

.modal-footer {
  justify-content: flex-start !important;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">Open modal</button>

<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">New message</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form>
          <div class="form-group">
            <label for="recipient-name" class="col-form-label">Recipient:</label>
            <input type="text" class="form-control" id="recipient-name">
          </div>
          <div class="form-group">
            <label for="message-text" class="col-form-label">Message:</label>
            <textarea class="form-control" id="message-text"></textarea>
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-primary">Send message</button>
      </div>
    </div>
  </div>
</div>

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

关于html - 如何将按钮移动到左侧?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68717962/

相关文章:

html - CSS 导航栏 UL 未居中

调整窗口大小时jquery图像调整大小

html - 粘性页脚 CSS

javascript - 在 HTML 的 &lt;script&gt; src 属性中传递 Javascript 全局变量

jquery - 跑马灯文本的位置设置

css - 固定宽度的 div 保持居中,即使浏览器宽度 < div 宽度

html - Bootstrap 4 - 在 anchor 标签内包装卡片图像在 IE 11 中创建空白

javascript - Bootstrap 4 - 附加侧边栏时无法保持相同的宽度

javascript - 使用jQuery(和 Bootstrap )启用/禁用提交按钮

html - 使用 body 元素作为页面包装器