Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I move display inline-block to the right?

Tags:

html

css

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/

like image 982
Shai UI Avatar asked Jul 20 '16 18:07

Shai UI


People also ask

How do you align inline elements to the right?

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.

How do I move a block to the right CSS?

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.

Can Inline Block be centered?

Inline block divs can be centered by applying text-align:center to their parent.

What is display inline block?

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.


2 Answers

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>
like image 57
Nenad Vracar Avatar answered Oct 15 '22 07:10

Nenad Vracar


use float right. This should work for you:

<div style='display:inline-block;position:relative;float:right;'>
right
</div>
like image 42
GunWanderer Avatar answered Oct 15 '22 07:10

GunWanderer