Can CSS Induce Line Breaks After Every Word in an Element?
In multilingual website development, maintaining consistency and readability is crucial. For instance, consider a website with multilingual text where the style dictates line breaks within certain phrases. However, manual line breaks using
tags pose challenges when dealing with non-technical contributors who may inadvertently alter the data during translation.
Is there a CSS solution to enforce line breaks after every word in an element, regardless of word length?
Despite the ability to achieve this using PHP, it's worth exploring potential CSS solutions.
CSS Solution: Word Spacing and Container Manipulation
To achieve the desired line break effect, employ the following CSS properties:
.one-word-per-line { word-spacing:; } .your-classname{ width: min-intrinsic; width: -webkit-min-content; width: -moz-min-content; width: min-content; display: table-caption; display: -ms-grid; -ms-grid-columns: min-content; }
In this approach, the .one-word-per-line class governs the spacing between words (word-spacing), effectively pushing each word to its own line. The .your-classname class sets various width and display properties that ensure the container's width is always wide enough to accommodate even a single character, hence triggering line breaks when necessary.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3