简体   繁体   中英

Vertical center align for a button in panel header with Bootstrap

I'm working on a Bootstrap 4 HTML page. I put a button in a panel header:

简单的详细信息页面

I need to put the button (and the title) in the middle of the panel header. How can I achieve this goal?

 <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script> <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" /> <div class="container p-4 "> <div class="card"> <div class="card-header"> <p class="float-left display-4">Administrator</p> <a href="#" class="btn btn-primary float-right" style="align-items: center" routerLink="../list" role="button"> <i class="fa fa-arrow-left"></i>&nbsp;Indietro</a> </div> <div class="card-body"> <form> <div class="form-group"> <label for="email">Email:</label> <input type="email" class="form-control" id="email"> </div> <div class="form-group"> <label for="pwd">Password:</label> <input type="password" class="form-control" id="pwd"> </div> <div class="form-group"> <label for="displayName">Display name:</label> <input type="displayName" class="form-control" id="displayName"> </div> <button type="submit" class="btn btn-primary float-right">Salva</button> </form> </div> </div> </div> 

Thanks

Try using display: flex; for your card header which is available in bootstrap and also instead of using float-right you can use ml-auto to move the button to the right (With the use of flex there is no need to use float properties). Hope this code helps

<!-- 
  Bootstrap docs: https://getbootstrap.com/docs
-->
<div class="container p-4 ">

  <div class="card">

    <div class="card-header d-flex flex-row align-items-center">
      <p class="float-left display-4">Administrator</p>
      <a href="#" class="btn btn-primary ml-auto" style="align-items: center" routerLink="../list" role="button">

    <i class="fa fa-arrow-left"></i>&nbsp;Indietro</a></div>
    <div class="card-body">
      <form>
        <div class="form-group">
          <label for="email">Email:</label>
          <input type="email" class="form-control" id="email">
        </div>
        <div class="form-group">
          <label for="pwd">Password:</label>
          <input type="password" class="form-control" id="pwd">
        </div>

        <div class="form-group">
          <label for="displayName">Display name:</label>
          <input type="displayName" class="form-control" id="displayName">
        </div>

        <button type="submit" class="btn btn-primary float-right">Salva</button>
      </form>
    </div>
  </div>
</div>

Just add display flex to your card-header class, then align-items: center

.card-header {
    padding: .75rem 1.25rem;
    margin-bottom: 0;
    background-color: rgba(0,0,0,.03);
    border-bottom: 1px solid rgba(0,0,0,.125);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM