Incorrect focus position in ContentEditable Div using placeholder in IE

I have Editable Div content with a place owner.

See fiddle .

[contenteditable=true]:empty:before {
  content: attr(placeholder);
}

#myDiv {
  border: 1px dashed #AAA;
  width: 290px;
  padding: 5px;
  text-align: center;
}
<div id="myDiv" contenteditable="true" placeholder="Enter text here..."></div>
Run codeHide result

The problem is this: When we open this script in Chrome and click on the div, we get the cursor focus in the div in the center. see pic below:

enter image description here

But when we do the same in IE, we get focus on last place. see below pic.

enter image description here

I also want to focus the cursor in the center in IE.

+4
source share
1 answer

, , position: absolute; div. IE11.

fiddle

:

[contenteditable=true] {
  position: relative;
}

[contenteditable=true]:empty:before {
  content: attr(placeholder);
  position: absolute;
  left: 0;
  right: 0;
  top: 4px;
  margin: auto;
}

#myDiv {
  border: 1px dashed #AAA;
  width: 290px;
  padding: 5px;
  text-align: center;
  height: 16px;
}
<div id="myDiv" contenteditable="true" placeholder="Enter text here..."></div>
Hide result
+1

Source: https://habr.com/ru/post/1684611/


All Articles