Create a Placeholder for Content Editable Divs
When you have a content editable div. Add an data
attribute. We're going to use placeholder
:
<div contenteditable="true" data-placeholder="(untitled)" class="title">
</div>
Then in your css, use a few pseudo classes to make it behave like a placholder:
.title:empty:not(:focus):before {
content: attr(data-placeholder)
}
Very cool! I (for whatever reason) never knew about :empty, :not, attr() or chaining multiple pseudo classes. Learned a lot in this little snippet :)
h/t @alejandroRINC0N
Tweet