styling div with contenteditable = "false"

Viewed 59

Following statement never changed the background color of div,

<div id="msg" contenteditable="false" style=" background-color: aqua;"></div>

While if I set contenteditable="true" then it works,

<div id="msg" contenteditable="true" style=" background-color: aqua;"></div>

How can I style contenteditable="false" ?

1 Answers

In your first example, the background colour is set for the div… but it has height: auto (the default) and no content to make auto resolve to anything more than 0. This leaves no visible pixels for the background to be painted on.

The contenteditable version gets an implied minimum height for the first line of content that the user can type into.

Related