-1

我需要将我的文本包装在div. 但如果我使用flex-wrap,它不会换行文本并且 div 的宽度会变大。我只想使包装的文本位于中心。

.flex-container {
  width: 150px;
  height: 150px;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: red;
}
<div class="flex-container">
  <span>longlonglonglonglonglonglong</span>
</div>

4

1 回答 1

1

您可以使用word-break: break-all

.flex-container {
  width: 150px;
  height: 150px;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: red;
  word-break: break-all;
}
<div class="flex-container">
  <span>longlonglonglonglonglonglong</span>
</div>

于 2018-01-17T08:41:43.740 回答