What is the difference between “word-break: break-all” versus “word-wrap: break-word” in CSS

前端 未结 10 1184
离开以前
离开以前 2020-11-22 07:39

I am currently wondering what is the difference between the two. When I used both they seem to break the word if it is not fitting the container. But why did W3C made two wa

10条回答
  •  北海茫月
    2020-11-22 07:58

    word-wrap: break-word recently changed to overflow-wrap: break-word

    • will wrap long words onto the next line.
    • adjusts different words so that they do not break in the middle.

    word-break: break-all

    • irrespective of whether it’s a continuous word or many words, breaks them up at the edge of the width limit. (i.e. even within the characters of the same word)

    So if you have many fixed-size spans which get content dynamically, you might just prefer using word-wrap: break-word, as that way only the continuous words are broken in between, and in case it’s a sentence comprising many words, the spaces are adjusted to get intact words (no break within a word).

    And if it doesn’t matter, go for either.

提交回复
热议问题