How to wrap long lines without spaces in HTML?

前端 未结 14 1902
旧巷少年郎
旧巷少年郎 2020-12-01 03:28

If a user types in a long line without any spaces or white space, it will break formating by going wider than the current element. Something like:

HA

14条回答
  •  孤城傲影
    2020-12-01 03:49

    I was trying to solve the same problem and I found de solution here:

    http://perishablepress.com/press/2010/06/01/wrapping-content/

    Solution: adding to the container the following CSS properties

    div {
        white-space: pre;           /* CSS 2.0 */
        white-space: pre-wrap;      /* CSS 2.1 */
        white-space: pre-line;      /* CSS 3.0 */
        white-space: -pre-wrap;     /* Opera 4-6 */
        white-space: -o-pre-wrap;   /* Opera 7 */
        white-space: -moz-pre-wrap; /* Mozilla */
        white-space: -hp-pre-wrap;  /* HP Printers */
        word-wrap: break-word;      /* IE 5+ */
    }
    

    The idea is using them all so you get better cross-browser compatibility

    Hope this helps

提交回复
热议问题