Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use the display:inline with text-align: right?

Tags:

css

xhtml

Example:

<td>
  <img src="..." />
  <img src="..." />
  <div style="text-align:right display:inline;">
    hello world!
  </div>
</td>
like image 819
Lenard Avatar asked Aug 04 '10 00:08

Lenard


People also ask

Does text-align work on inline?

Even though the property says “text” align, it affects all elements inside the block-level element that are either inline or inline-block elements. The property only affects the content inside the element to which it is applied, and not the element itself.

How do I align an inline element to the right?

Make sure you set the text-align property for the first list item to "left" (ul li:first-child), and set the text-align property for the other list items (ul li) to "right". That aligns them to the left and to the right but on two suppurate lines.

How do you align text in CSS inline?

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 you move inline-block elements to the right?

You can use Flexbox instead and set margin-left: auto on inner div to move it to right. Show activity on this post.


2 Answers

Well technically you can but it will have no effect. Display: inline will display the div as an inline element (like an a or span) and therefore not have a width - it will shrink to fit the text.

If you are trying to display inline text on the right try using float: right;

Also, in your code you missed out an ";" after the text-align: right.

like image 59
Danny Nimmo Avatar answered Nov 15 '22 08:11

Danny Nimmo


You can wrap the element which you want to have display:inline inside another div with dir="rtl"

<div dir="rtl">
  <div style="display: inline">Align to the right</div>
</div>

Demo: https://jsfiddle.net/guya/xwhodc0s/

like image 28
guya Avatar answered Nov 15 '22 08:11

guya