[whatwg] Should editable elements have placeholder attribute?

David Young dyoung at pobox.com
Fri Aug 31 18:22:07 PDT 2012


On Thu, Aug 30, 2012 at 11:44:46AM +0300, Jussi Kalliokoski wrote:
> On Thu, Aug 30, 2012 at 11:43 AM, Jussi Kalliokoski <
> jussi.kalliokoski at gmail.com> wrote:
> 
> > It's pretty simple to make a naive placeholder for contenteditable
> > elements with CSS:
> >
> > [contenteditable]:not(:focus):empty::after {
> >         content: attr(data-placeholder);
> >         color: #ccc;
> > }
> >
> > I call it a bit naive because it turns out that if you have insert a line
> > break in the box, there will always be one line break inside the element
> > (even if you clean it empty), making the element non-empty and hence the
> > placeholder won't show.
> >
> > You can try it in action here:
> > file:///home/jussi/code/contenteditable/index.html
> >
> 
> Whoooops, yeah, I'm pretty sure that won't work, try this instead:
> http://labs.avd.io/contenteditable/

This demonstrates some unexpected contenteditable results on
Chrome 21.0.1180.82 under Mac OS X.  I cannot seem to return the
contenteditable to the empty state again---i.e., to the state where the
placeholder shows---using Chrome.  All that I have entered is a space.
Backspacing over the space leaves a <br>.  Inserting a space again
deletes the <br>.

In Firefox 3.6.19 it is necessary to insert two spaces before a <br>
appears; the <br> cannot be deleted, not even by inserting a space. :-)

Dave

-- 
David Young
dyoung at pobox.com    Urbana, IL    (217) 721-9981



More information about the whatwg mailing list