2 回答
TA贡献1891条经验 获得超3个赞
如果你想在一行中有相同数量的字母,你应该使用等宽字体。
如果您还希望在任意两个字符之间换行 - 使用word-break: break-all(MDN):
body {
font-family: Courier New;
}
.container {
width: 143px;
height: 150px;
border: 2px dashed #333;
margin-bottom: 16px;
}
.container-header {
padding: 8px;
height: 16px;
border-bottom: 2px dashed #333;
}
.container-content {
padding: 8px;
}
.keep-all {
word-break: break-all;
}
.break-all {
word-break: break-all;
}
.break-word {
word-break: break-word;
}
<div class="container">
<div class="container-header">keep-all</div>
<div class="container-content">
abcdefghij klmnopqrstuvwxyz 01234 56789
</div>
</div>
<div class="container">
<div class="container-header">break-all</div>
<div class="container-content break-all">
abcdefghij klmnopqrstuvwxyz 01234 56789
</div>
</div>
<div class="container">
<div class="container-header">break-word</div>
<div class="container-content break-word">
abcdefghij klmnopqrstuvwxyz 01234 56789
</div>
</div>
TA贡献2011条经验 获得超2个赞
也许你可以使用 CSS Word Wrap https://developer.mozilla.org/pt-BR/docs/Web/CSS/word-wrap
添加回答
举报