Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixed padding in contenteditable element

The padding of a textarea is always fixed. When the text content of the textarea is scrolled, the padding remains near the edges.

The padding of a contenteditable element behaves differently. When the text content of the element is scrolled, the padding moves with it.

This demo illustrates the difference.

Can a contenteditable element by styled so its padding behaves more like textarea padding, staying in place while the text content is scrolled?

like image 202
John Karahalis Avatar asked Dec 20 '14 04:12

John Karahalis


People also ask

What is false about Contenteditable attribute?

The contentEditable property of the HTMLElement interface specifies whether or not the element is editable. This enumerated attribute can have the following values: ' true ' indicates that the element is contenteditable . ' false ' indicates that the element cannot be edited.

How do I stop Enter key in Contenteditable?

$('p[contenteditable]'). keyup(function(e) { return e. which !== 13 });

What is the function of Contenteditable attribute?

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

What is the function of Contenteditable attribute Mcq?

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.


1 Answers

The answer to your specific question of whether a non-textarea "contenteditable" block level element's padding can behave like a textarea's is "no."

There is likely a way to achieve this look by adding additional elements to your div, but the padding of your div will always behave as padding is designed to.

Your padding issue has nothing to do with the "contenteditable" property. You could take the "cnotenteditable=true" off of your div, and the padding behaves the same way. Padding "clears an area around the content" of the element, which in this example is the text in your div. The padding will always remain around the text, not around the inside of the div.

like image 199
scmccarthy22 Avatar answered Oct 15 '22 05:10

scmccarthy22