I have an editable div with :before
and :after
css pseudo-elements.
The :before
sets a prompt in the div
The :after
acts like a placeholder
When the user clicks in an empty div, the cursor is placed before the "prompt" content.
Once the user starts typing the :after
content disappears and the cursor is in the right spot.
Is there a way to have the cursor positioned after the content when an empty div is selected? What is interesting is if there is any text in the div and you select the div the cursor goes to the end (as I want).
Any thoughts/help would be most appreciated.
div[data-prompt][contenteditable=true]:before {
content: attr(data-prompt);
font-family: 'Open Sans', sans-serif;
color: black;
}
div[data-placeholder]:empty:after {
content: attr(data-placeholder);
color: black;
}
<div contenteditable='true' id="tbl01_r2c2" data-type="2" data-prompt="I will " data-placeholder="..."></div>
Cursor position when empty div is selected
Also note that the "prompt" will not always be the same length.