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 ways to do it?
相关问题
- Adding a timeout to a render function in ReactJS
-
Why does the box-shadow property not apply to a
- Add animation to jQuery function Interval
- jQuery hover to slide?
- Issue with star rating css
word-wrap: break-word
recently changed tooverflow-wrap: break-word
word-break: break-all
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.
word-wrap
has been renamed tooverflow-wrap
probably to avoid this confusion.Now this is what we have:
overflow-wrap
Possible values:
normal: Indicates that lines may only break at normal word break points.
break-word: Indicates that normally unbreakable words may be broken at arbitrary points if there are no otherwise acceptable break points in the line.
source.
word-break
source.
Now back to your question, the main difference between overflow-wrap and word-break is that the first determines the behavior on an overflow situation, while the later determines the behavior on a normal situation (no overflow). An overflow situation happens when the container doesn't have enough space to hold the text. Breaking lines on this situation doesn't help because there's no space (imagine a box with fix width and height).
So:
overflow-wrap: break-word
: On an overflow situation, break the words.word-break: break-all
: On a normal situation, just break the words at the end of the line. An overflow is not necessary.In addition to the previous comments browser support for
word-wrap
seems to be a bit better than forword-break
.This is all i can find out. Not sure if it helps, but thought I'd add it to the mix.
WORD-WRAP
This property specifies whether the current rendered line should break if the content exceeds the boundary of the specified rendering box for an element (this is similar in some ways to the ‘clip’ and ‘overflow’ properties in intent.) This property should only apply if the element has a visual rendering, is an inline element with explicit height/width, is absolutely positioned and/or is a block element.
WORD-BREAK
This property controls the line breaking behavior within words. It is especially useful in cases where multiple languages are used within an element.
At least in Firefox (as of v24) and Chrome (as of v30), when applied to content in a
table
element:word-wrap:break-word
will not actually cause long words to wrap, which can result in the table exceeding the bounds of its container;
word-break:break-all
will result in words wrapping, and the table fitting within its container.
jsfiddle demo.
word-break:break-all
:word to continue to border then break in newline.
word-wrap:break-word
:At first , word wrap in newline then continue to border.
Example :