Right align element in div class

前端 未结 3 1737
逝去的感伤
逝去的感伤 2020-12-18 20:16

I am using angular 2 with Bootstrap 4 and Angular Material. However, I am having trouble right align the elements inside my container div. I want both my button and text to

相关标签:
3条回答
  • 2020-12-18 20:42

    I've removed the class pull-right class from both the button and the p tag and added text-right class to the div.container.

    I think this is what you need.

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
    <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
    
    
    
    <div class="container text-right">
        <p class="d-inline">Some text</p>
        <button type="button" class="btn btn-primary d-inline">+</button>
    </div>

    0 讨论(0)
  • 2020-12-18 20:57

    In Bootstrap 4, pull-right has been replaced with float-right.

    If float-right is not working, remember that Bootstrap 4 is now flexbox, and many elements are display:flex which can prevent float-right from working. In some cases, the utility classes like align-self-end or ml-auto work to right align elements that are inside a flexbox container like a Bootstrap 4 .row, Card or Nav. The ml-auto (margin-left:auto) is used in a flexbox element to push elements to the right.

    Also, remember that text-right still works on inline elements.

    Bootstrap 4 align right examples

    0 讨论(0)
  • 2020-12-18 21:03

    You are not doing anything wrong. Just copy and paste your code in any online bootstrap editor, you will get the right result. But you can write it in a more structured way

    HTML code:

            <div class="container">
              <div class="row">
                <div class="col-md-12 .asdf">
                  <button type="button" class="btn btn-primary pull-right">+</button>
                  <p class="pull-right">Some text</p>
                </div>
              </div>
            </div>
    

    CSS code

    .asdf {
      margin-left:auto; 
      margin-right:0;
    }
    
    0 讨论(0)
提交回复
热议问题