33

I was recently fiddling with contenteditable in a webpage and got irritated when I needed to set a large number of span tags with it (I ended up using JavaScript to do it). If only I could set it via CSS...

Does anyone know the rationale behind why contenteditable was designed as an attribute rather than a style?

Vanwaril
  • 7,380
  • 6
  • 33
  • 47
  • you could have put a `div` around the spans and give that `div` `contentEditable`, as `contentEditable` is inherited down all apans would have been editable as well. – Bazzz Apr 20 '12 at 09:07
  • 1
    I didn't want edits 'overflowing' outside each span element. – Vanwaril Apr 20 '12 at 09:08
  • 2
    In order to use contentEditable you *need* javascript to read back the edited contents, so I don't understand why it bothers you to use it to enable the editing. – AlfonsoML Apr 20 '12 at 12:36

4 Answers4

34

Most people would argue that contentEditable defines behaviour, rather than style (which is true).

WebKit has a CSS property that is similar to contentEditable: -webkit-user-modify.

Alp
  • 29,274
  • 27
  • 120
  • 198
Andy E
  • 338,112
  • 86
  • 474
  • 445
23

try

span {
    -webkit-user-modify: read-write;
    -moz-user-modify: read-write;
    user-modify: read-write;
}

it worked on Firefox, Chrome. You can find more info about user-modify

crazyjune
  • 349
  • 3
  • 5
9

The ability for the user to edit some content or not isn't anything to do with presentation.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
9

styles are optional; you can (in theory) render every page without CSS and it should still work fine. In fact, that's what many text-only browsers, or audio-only browsers do.

contentEditable changes the behavior of elements. A browser that doesn't use style, but interprets JavaScript, should still benefit from the property.

phihag
  • 278,196
  • 72
  • 453
  • 469