在使用flex布局进行写页面时,发现如果长文本超出盒子大小不会自动换行
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box{
display: flex;
width: 200px;
height: 200px;
background-color: pink;
}
</style>
</head>
<body>
<div class="box">
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
</div>
</body>
</html>
仅靠用
word-wrap:break-word;
解决不了这个问题
通过查询了解到了css的word-break属性
word-break 属性规定自动换行的处理方法。通过使用 word-break 属性,可以让浏览器实现在任意位置的换行。
word-break: normal|break-all|keep-all;
normal;(默认值) //使用浏览器默认的换行规则
break-all; //允许在单词内换行。
keep-all; //只能在半角空格或连字符处换行。
添加
word-break:break-all;
成功换行