playground
This is a simplified version of my problem.
seems like I cannot put a positioned pseudo element inside a contentEditable and yet have the caret positioned in the correct place when clicking to get focus on the contentEditable element.
div{ padding:10px; border:1px solid #CCC; height:120px; position:relative; }
div::before{
position:absolute;
top:10px;
left:10px;
content:"placeholder";
color:#AAA;
transition:.2s;
opacity:0;
}
div:empty::before{
opacity:1;
}
<div contentEditable></div>
UPDATE - FOUND THE REPORTED BUG:
please vote for this bug to be repaired - https://bugzilla.mozilla.org/show_bug.cgi?id=904846
For me this was only a problem when the box was empty. So I seeded it with a
<br>
:More info here: https://bugzilla.mozilla.org/show_bug.cgi?id=550434
There is a problem when you put the
:after
element to absolute. I can not figure out why. But if you just place it relative the problem is gone.I've updated your fiddle: http://jsfiddle.net/NicoO/Lt3Wb/1/
Here is the new CSS (with some experimental additions)
The only problem that remains is, that you can focus behind the text of the
:before
element. That'll be why you wanted it absolute. Interessting also: If you put the pseudo element tofloat: left;
it shows the same behaviour as onposition:absolute;
.Update
When you are forced to use absolute on peseudo elements, there seems to be only one solution at the moment. Define another padding for the box as long as it is empty and focused. Playground: http://jsfiddle.net/NicoO/Lt3Wb/5/
One work around of this problem is to wrap the content-editable inside a DIV and give to this DIv a fixed height.
That is, if you have a configuration like this :
Then the CSS can be the following :