阅读一些以前的帖子我来了解一下,在表格中包装文字我们需要添加table-layout: fixed
和word-wrap: break-word
。但是,这是行不通的,如果没有任何固定宽度表如何强制宽度自动表上的文字换行?
.container {
width: 30%;
padding: 5px;
background: #888;
border: 1px dotted red;
}
.table {
display: table;
table-layout: fixed;
width: auto;
word-wrap: break-word;
}
<div class="container">
<div class="table">
<a href="#">unbreajabelunbreajabelunbreajabelunbreajabelunbreajabelunbreajabelunbreajabelunbreajabelunbreajabelunbreajabelunbreajabelunbreajabelunbreajabelunbreajabelunbreajabelunbreajabelunbreajabelunbreajabelunbreajabelunbreajabel</a>
</div>
</div>
在我的网站我有几分的情况,我无法给元素固定宽度与显示表。
如何实现换行以避免文本溢出?
@Pete在实际网站中,它的引导列宽度以百分比表示宽度。我在这里添加了固定宽度以避免不必要的标记。我现在已经把它变成了问题本身的百分比。 – user31782