Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`contenteditable = true` height issue in FireFox

When there is an empty div with contenteditable="true":

CSS:

[contenteditable="true"] {
    border: 1px dashed #dedede;
    padding: 3px;
}

HTML:

<div contenteditable="true">
    <!-- blank by default -->
</div>

In IE and Chrome, it shows the height like a normal input field with small padding. In Firefox, it only shows that 3px padding I added in the styles. W/o that, it collapses and is only as tall as the border.

Do you know if this is a Firefox bug? Can you suggest a way to handle it?

like image 625
TheLettuceMaster Avatar asked May 07 '14 23:05

TheLettuceMaster


People also ask

Is Contenteditable safe to use?

Its totally secure. The contenteditable attribute is an enumerated attribute whose keywords are the empty string, true, and false.

What is the role of Contenteditable true attribute?

The contenteditable attribute specifies whether the content of an element is editable or not.

What is Contenteditable?

The contenteditable global attribute is an enumerated attribute indicating if the element should be editable by the user. If so, the browser modifies its widget to allow editing.

How do I make my website Contenteditable?

Answer: Use the HTML5 contenteditable Attribute You can set the HTML5 contenteditable attribute with the value true (i.e. contentEditable="true" ) to make an element editable in HTML, such as <div> or <p> element.


1 Answers

workaround:

[contenteditable='true']:before {
    content: "\feff ";
}

CSS2 section 10.6.3:

The element's height is the distance from its top content edge to the first applicable of the following:

  1. the bottom edge of the last line box, if the box establishes a inline formatting context with one or more lines
  2. the bottom edge of the bottom (possibly collapsed) margin of its last in-flow child, if the child's bottom margin does not collapse with the element's bottom margin
  3. the bottom border edge of the last in-flow child whose top margin doesn't collapse with the element's bottom margin
  4. zero, otherwise

For this empty div,

1 through 3 are not applicable, since the div is empty. It has no line boxes or children. Item 4 therefore applies.

The workaround enforces at least one line box inside the div, so that it gets nonzero height.

like image 143
guest Avatar answered Oct 19 '22 07:10

guest