word-break和word-wrap的用处和区别

word-break:break-all; 和 word-wrap:break-word;两种写法都是让英文句子在父级宽度不够的情况下换行。

两个属性都同样是让文字换行,但存在着细微的区别,大部分时候刚接触到这两个属性时会无法区别两个的区别

下面讲一下两者的区别:

word-wrap:break-word; 作用是强制让文字换行。 一般情况下当父级宽度不够的时候,不管英文单词自动换行是当一整个单词不够放时,整个单词一起换行到下一行,

看似很合理的写法,但是在有些情况下会出现不可预期的情况。 就是当一个英文单词的长度超过了父级容器长度是,英文单词还是会显示一整个单词而导致超出容器范围。

还有的情况是,当遇到一个单词很长时,次单词自动换行,也会使上一行空出很多空间浪费了。

在这种情况下,IE创造出一种新的属性,word-break:break-all; 它强制文字换行无论一句话到达父级容器宽度的时候是不是一整个单词,都会强制换行,使单词断句,

如果碰上一个单词超出父级容器宽度,会使单词断开并换行。

兼容性:

word-break:break-all; 只不兼容opera,其他浏览器都兼容

word-wrap:break-word;兼容所有浏览器

两种写法的各有作用,应视情况做出选择!

时间: 2024-11-16 18:07:10

word-break和word-wrap的用处和区别的相关文章

word break和word wrap

默认情况下,如果同一行中某个单词太长了,它就会被默认移动到下一行去: word break(normal | break-all | keep-all):表示断词的方式 word wrap(normal | break-word):表示是否要断词 word wrap break-word   [要断词] 独占一行(默认情况下单词太长就会被换到下一行去,所以就独占一行了)的单词被断开成多行, 默认值normal,则不断词,而是一行显示,超出容器 word break break-all:和上面相比

Word Break && Word Break II

Word Break && Word Break II Word Break 题目: Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For example, given s = "leetcode", dict = ["

Word Break II

https://oj.leetcode.com/problems/word-break-ii/ Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences. For example, givens = "catsanddog

[leecode]Word Break II

Word Break II Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences. For example, givens = "catsanddog",dict = ["cat", &q

[C++]LeetCode: 113 Word Break II (DP && Backtacking) 求解拆分组合

题目: Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences. For example, given s = "catsanddog", dict = ["cat", "cats

leetcode[140] Word Break II

这题是上一题的加强版,这里需要返回的是所有可能的分割词.例如: s = "catsanddog",dict = ["cat", "cats", "and", "sand", "dog"]. A solution is ["cats and dog", "cat sand dog"]. 先用dp求得每个起点到终点是否符合word break 1中的条

Leetcode dfs Word Break II

Word Break II Total Accepted: 15138 Total Submissions: 92228My Submissions Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences. For ex

Leetcode dp Word Break

Word Break Total Accepted: 22281 Total Submissions: 105657My Submissions Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For example, given s = "leetcod

【leetcode】Word Break II

Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences. For example, givens = "catsanddog",dict = ["cat", "cats"

【leetcode】Word Break

Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For example, givens = "leetcode",dict = ["leet", "code"]. Return true because &