使用Bootstrap 4模态使标签正确对齐

问题描述 投票:4回答:4

如何使此标签对齐?我只能把它对齐了。我必须将justify-content: center的bootstrap 4默认值覆盖到justify-content: right !important;但它与左边对齐。我怎样才能将它对齐?

<div class="modal-body">
    <form class="form-horizontal">
        <div class="form-inline">
            <label class="col-md-4">Type</label>
            <input class="col-md-8" type="email" class="form-control">
        </div>
    </form>
</div>

CSS:

div.form-inline label.col-md-4 {
    justify-content: right !important; 
}

enter image description here

css twitter-bootstrap label bootstrap-4
4个回答
5
投票

您需要将其更改为:

div.form-inline label.col-md-4{
    justify-content: flex-end;
}

justify-content: right不是有效值。


0
投票

Bootstrap 4转移到flex布局而不是block。您必须使用justify-content: flex-end为您的情况。

$('#myModal').on('shown.bs.modal', function () {
  $('#myInput').focus()
})
div.form-inline label.col-md-4{
  justify-content: flex-end; 
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">

<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.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
  Launch demo modal
</button>

<!-- Modal -->
<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">Modal title</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 class="form-horizontal">
            <div class="form-inline">
              <label class="col-md-4">Type</label>
              <input class="col-md-8" type="email" class="form-control">
            </div>
          </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

0
投票

justify-content: flex-end不适合我(Bootstrap 4.1.0),但text-align: right工作:

<style>
label { text-align: right }
</style>

或者在.css文件中:

.col-form-label { text-align: right }

0
投票

将类“text-right”添加到标签

<div class="modal-body">
    <form class="form-horizontal">
        <div class="form-inline">
            <label class="col-md-4 text-right">Type</label>
            <input class="col-md-8" type="email" class="form-control">
        </div>
    </form>
</div>
© www.soinside.com 2019 - 2024. All rights reserved.