Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why "text-align: right" doesn't work on empty contenteditable element in Firefox?

Consider the following: (Live Demo)

HTML:

<div contenteditable></div>

CSS:

div {
  text-align: right;
}

When you click the div in Firefox, the cursor is located at the left (looks like text-align: right; has no effect). But, if you start typing, text-align: right; starts taking effect.

Why is that? Any ideas how to fix this?

like image 390
Misha Moroshko Avatar asked Jun 07 '13 12:06

Misha Moroshko


People also ask

Does text-align work on block elements?

The text-align property in CSS is used for aligning the inner content of a block element. These are the traditional values for text-align: left – The default value. Content aligns along the left side.

What elements does text-align work on?

Note. The text-align property only aligns the inline content (ie: text) of an element within its parent block element. The text-align property does not align a block element itself, only the inline content.

How do I align text to the right center?

Align the text left or right Select the text that you want to align. On the Home tab, in the Paragraph group, click Align Left or Align Right .

Is text-align left default?

The left value of the text-align property is the default. So, every content inside a block-level element is aligned to the left by default.


1 Answers

This can be achieved using a simple change like this:

<div contenteditable>&nbsp;</div>

We're forcing a blank space in it.

Well if the space matters, I think you have a problem. But I hope this helps :)

like image 94
itsols Avatar answered Oct 19 '22 08:10

itsols