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 be aligned to the right hand side
Here is what the code that I have tried to produce the result as shown in the photo
<div class="container">
<div class="pull-right">
<p class="d-inline pull-right">Some text</p>
<button type="button" class="btn btn-primary pull-right">+</button>
</div>
</div>
I have also tried this solution from StackOverflow
<div class="container">
<div class="asdf">
<p class="d-inline pull-right">Some text</p>
<button type="button" class="btn btn-primary pull-right">+</button>
</div>
</div>
.asdf {
margin-left:auto;
margin-right:0;
}
Both of these solutions does not move the elements to the right. What am I doing wrong?
In Bootstrap 4,
pull-right
has been replaced withfloat-right
.If
float-right
is not working, remember that Bootstrap 4 is now flexbox, and many elements aredisplay:flex
which can preventfloat-right
from working. In some cases, the utility classes likealign-self-end
orml-auto
work to right align elements that are inside a flexbox container like a Bootstrap 4 .row, Card or Nav. Theml-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
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:
CSS code
I've removed the class
pull-right
class from both thebutton
and thep
tag and addedtext-right
class to thediv.container
.I think this is what you need.