使用flex布局,文字不换行问题。
使用了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
·
使用了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>
.aaa{
border: 1px solid red;
}
.div1{
word-wrap: break-word; /*使用css换行*/
word-break: normal;
}
</style>
</head>
<body>
<div>
<div class="aaa div1" style="width: 200px; height: 200px; display: flex;">
dfjkskldjfklsjdfklsjdjhdfkjlshjkhdfjksdhfjkslhdfjshdljfhskljdf
</div>
</div>
</body>
</html>
但是可以看到换行失败:具体原因是 当父元素设置display: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>
.aaa{
border: 1px solid red;
}
.div1{
word-wrap: break-word;
word-break: normal;
width: 100%;
}
</style>
</head>
<body>
<div>
<div class="aaa" style="width: 200px; height: 200px; display: flex;">
<span class="div1"> dfjkskldjfklsjdfklsjdjhdfkjlshjkhdfjksdhfjkslhdfjshdljfhskljdf</span>
</div>
</div>
</body>
</html>
换行成功
更多推荐
已为社区贡献1条内容
所有评论(0)