Chrome on macOS and Chromium on Linux don’t sensibly position the caret when clicking inside an editable area for larger line heights.
In this example, we set a value for line-height
for <span>
elements. Leaving it off and inheriting from the parent element is not possible because of other app requirements, mainly the use of Quill.js rich text editor. There may be multiple <span>
per line with differing font sizes, but no nested elements.
p {
display: inline-block;
margin: 0;
background: lightgrey;
}
span {
line-height: 2.5;
font-size: 50px;
background: lightblue;
}
span.small {
font-size: 25px;
}
<p contenteditable><span>some </span><span class="small">text</span><br/><span>some text</span></p>
In Firefox, if you click into the gray area (marking the <p>
element), the caret will always be positioned at the nearest character. If you click between lines, the caret also positions sensibly.
In Chrome, the caret positions at the nearest character only if you click inside the blue area (marking the element). In the grey area, the caret ends up at the start of the next line, or at the end of the last line if you click below the last span.
How can you replicate the Firefox behavior with Chrome?
Note: giving the spans a display: inline-block
as recommended here does not solve the problem.
` elements, so for them it is a justified expectation that every click inside that area will position the caret consistently.
– ccprog Jul 06 '19 at 22:13