I have a div that's within a display:inline-block. How do I move it to the right?
<div style='width:100%'>
left
<div style='display:inline-block;position:relative;right:0px'>
right
</div>
</div>
https://jsfiddle.net/foreyez/y5dt2prj/
To set text alignment in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <p> tag, with the CSS property text-align for the center, left and right alignment.
Absolute Positioning Move Left - Use a negative value for left. Move Right - Use a positive value for left. Move Up - Use a negative value for top. Move Down - Use a positive value for top.
Inline block divs can be centered by applying text-align:center to their parent.
The display: inline-block Value Compared to display: inline , the major difference is that display: inline-block allows to set a width and height on the element. Also, with display: inline-block , the top and bottom margins/paddings are respected, but with display: inline they are not.
You can use Flexbox
instead and set margin-left: auto
on inner div to move it to right.
<div style='display:flex;'>
left
<div style='margin-left: auto;'>
right
</div>
</div>
use float right. This should work for you:
<div style='display:inline-block;position:relative;float:right;'>
right
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With