Smarter word break in CSS?

前端 未结 4 1640
情歌与酒
情歌与酒 2021-01-30 20:02

If I just put word-break: break-all on an element, I often end up with this:

Hello people, I am typing a mes
sage that\'s too long to f

4条回答
  •  粉色の甜心
    2021-01-30 20:40

    For a lot of our projects we usually add this where necessary:

    .text-that-needs-wrapping {
        overflow-wrap: break-word;
        word-wrap: break-word;
        -ms-word-break: break-all;
        word-break: break-word;
        -ms-hyphens: auto;
        -moz-hyphens: auto;
        -webkit-hyphens: auto;
        hyphens: auto;
    }
    

    It handles most odd situations with different browsers.

提交回复
热议问题