Convert white space to line break

Is it possible to add line breaks in each space using CSS?

For example, if I have the line "Format It" , I would like to display it as

 Format It 

using CSS.

+6
source share
2 answers

You can use the word-spacing . It defines the space between words. If you set it to the size of the container, this will force a line break ...

Since it does not accept percentage values, you can use relative values ​​such as vw .

 div { word-spacing: 100vw; } 

http://jsfiddle.net/ApL3h/

+10
source

The solution is to make it not wide enough, standard white-space processing will make the lines wrap:

 p { width:1px; } 

demonstration

But it really depends on your use case and specific needs.

+4
source

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


All Articles