ARTICLE AD BOX
I want to create a textbox with the following requirements:
width: 16 columns (characters) height: 3 lines max chars: 48 lines should always break after 16 characters, no matter what char has been enteredThe best I have come up with is this solution:
However, I am facing a problem. If exactly 16 characters followed by a space character are entered, the last two chars (in my example the 8 and the space) jump down to the next line (see middle box in the snippet). I want the "8" (the 16th char) to remain on the first line, whereas the space (the 17th char) breaks down to the next line. This problem occurs with most browsers, however Firefox 147.0.2 is behaving correctly. Any ideas?
17.5k3 gold badges33 silver badges53 bronze badges
2892 silver badges12 bronze badges
4
To achieve this enforces a 16×3 character grid in a <textarea> by using overflow-wrap: anywhere to allow breaks at any point, combined with box-sizing: content-box so the width matches exactly 16 characters. maxlength="48" limits input, and spellcheck="false" prevents browser highlights from shifting alignment. Manual newlines are blocked to maintain consistent character flow.
New contributor
lester is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
Changing whitespace:break-spaces to whitespace:break-word seems to work. I also removed, the width attribute, since in my Chrome it's showing 14 characters.
1871 silver badge8 bronze badges
Explore related questions
See similar questions with these tags.
