Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize automatic line wrapping and adaptive text in HTML

Shulou Source: shulou.com Published: 2022-06-02 00:47:54 09月30日 Update

This article introduces the relevant knowledge of "how to achieve automatic line wrapping and adaptive text in HTML". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Pre, remove the scroll bar.

Pre does not automatically wrap lines when displaying text content. You can add some CSS to solve the problem at this time:

Ourjs this is very very very very very very very very very very very very very very very logn contents.pre {word-wrap: break-word; white-space: pre-wrap; padding: 9.5px; background-color: # f5f5f5; border: 1px solid # ccc;}

Textarea makes content highly adaptive:

Textarea can also retain content formatting like prev, but the element height is fixed and cannot be adjusted with CSS. At this point, you can take advantage of the scrollHeight attribute.

Var textarea = document.getElementsByTagName ('textarea') [0]; textarea.setAttribute (' style','height:'+ (textarea.scrollHeight + 12) + 'px')

12px's padding is added here.

"how to achieve automatic line wrapping and adaptive text in HTML" is introduced here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Content text height more knowledge practicality achievement next elements dilemmas reality attributes situations articles formats cases editing websites industries processes Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info NVidia Docker Shulou Technology Apple