html - 文本没有包裹在均匀分布、宽度均匀的 flexbox 中

标签 html css flexbox

这是一个示例:https://jsfiddle.net/gxhb2xnu/1

.container {
  display: flex;
  flex-direction: row;
  width: 100%;
  height: 100vh;
}

.column {
  flex: 1;
  background: red;
  margin: 0 4px;
  height: 100%;
}
<div class="container">
  <div class="column">foõ foõ foõ foõ foõ foõ</div>
  <div class="column">foõ</div>
  <div class="column">foõ</div>
  <div class="column">foõ</div>
  <div class="column">foõfoõfoõfoõfoõfoõfoõfoõfoõfoõfoõfoõfoõfoõfoõfoõfoõ</div>
</div>

如您所见,最后一列会调整其宽度以容纳文本。我希望每一列都具有相同的宽度,并且只是将中间单词分隔到下一行。

我尝试了flex-basis: 0word-wrap: break-word;,但似乎没有影响。

最佳答案

There were few mistakes that I have corrected.

  1. 修复了 column divs 中的 flex 属性
  2. 使用word-break:break-word

Below is the working code.

.container {
  display: flex;
  flex-direction: row;
  width: 100%;
  height: 100vh;
}

.column {
  flex-grow: 1;
  flex-basis: 0;
  background: red;
  margin: 0 4px;
  height: 100%;
  word-break: break-word;
}
<div class="container">
  <div class="column">foõ foõ foõ foõ foõ foõ</div>
  <div class="column">foõ</div>
  <div class="column">foõ</div>
  <div class="column">foõ</div>
  <div class="column">foõfoõfoõfoõfoõfoõfoõfoõfoõfoõfoõfoõfoõfoõfoõfoõfoõ</div>
</div>

关于html - 文本没有包裹在均匀分布、宽度均匀的 flexbox 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43555564/

相关文章:

javascript - 嗨,我无法让 CSS 旋转动画工作?使用最新版本。更新 : running on Chrome

javascript - 如何使用 CSS 在图像上创建这种效果

css - 位置为 : relative with SVG clip paths not displaying in Safari 的元素

html - 什么会导致 flex 容器行之间出现空格?

html - 在网格中使用 flexbox 时在 div 之间添加空间

javascript - 如何在 PHP 中使用 SVG 绘制正方形?

html - 如何在 Bootstrap 中添加固定宽度后使 div 响应

html - CSS 规则应用了两次 - 覆盖 !important

jQuery.animate();没有跑?甚至不跳,什么都没有发生

html - chrome 中忽略了 flex 元素内的最小高度