converting white space into line break

后端 未结 2 464
無奈伤痛
無奈伤痛 2021-01-18 02:19

Is it possible to add a line break on each white space using CSS?

For example, if I have string \"Format It\" I would like to display it like

         


        
相关标签:
2条回答
  • 2021-01-18 03:02

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

    Since it doesn't accept percentual values, you can use relative values like vw.

    div {
        word-spacing: 100vw;
    }
    

    http://jsfiddle.net/ApL3h/

    0 讨论(0)
  • 2021-01-18 03:25

    A solution would be to make it not wide enough, the standard white-space handling will make the lines wrap :

    p {
      width:1px;
    }
    

    demonstration

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

    0 讨论(0)
提交回复
热议问题