I use this code to right align a button.
It is not always so simple and sometimes the alignment must be defined in the container and not in the Button element itself !
For your case, the solution would be
<div style="text-align:right; width:100%; padding:0;">
<input type="button" value="Click Me"/>
</div>
I have taken care to specify width=100%
to be sure that <div>
take full width of his container.
I have also added padding:0
to avoid before and after space as with <p>
element.
I can say that if <div>
is defined in a FSF/Primefaces table's footer, the float:right
don't work correctly because the Button height will become higher than the footer height !
In this Primefaces situation, the only acceptable solution is to use text-align:right
in container.
With this solution, if you have 6 Buttons to align at right, you must only specify this alignment in container :-)
<div style="text-align:right; width:100%; padding:0;">
<input type="button" value="Click Me 1"/>
<input type="button" value="Click Me 2"/>
<input type="button" value="Click Me 3"/>
<input type="button" value="Click Me 4"/>
<input type="button" value="Click Me 5"/>
<input type="button" value="Click Me 6"/>
</div>
To keep the button in the page flow:
<input type="button" value="Click Me" style="margin-left: auto; display: block;" />
(put that style in a .css file, do not use this html inline, for better maintenance)
In my case the
<p align="right"/>
worked fine
a modern approach in 2019 using flex-box
with div tag
<div style="display:flex; justify-content:flex-end; width:100%; padding:0;">
<input type="button" value="Click Me"/>
</div>
with span tag
<span style="display:flex; justify-content:flex-end; width:100%; padding:0;">
<input type="button" value="Click Me"/>
</span>
<div style = "display: flex; justify-content:flex-end">
<button>Click me!</button>
</div>
<div style = "display: flex; justify-content: flex-end">
<button>Click me!</button>
</div>