html - CSS Float 水平溢出

标签 html css recursion overflow

我有以下 jsfiddle:https://jsfiddle.net/CLight/1emh82cv/

这是一个递归结构,它由两个共享顶行的双胞胎单元和一个共享第二行/底行的单元格组成。这三个单元格将被递归地插入到底部单元格中。 我正在尝试弄清楚如何让单元格在溢出时水平扩展,而不会破坏结构。非常感谢。

这是 html:

 <div class="cell-main">
  <div class="cell-left">
    testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttestte
  </div>
  <div class="cell-right">
    test
  </div>
  <div class="cell-bottom">
    <div class="cell-left">
      test
    </div>
    <div class="cell-right">
      test
    </div>
    <div class="cell-bottom">

      <div class="cell-left">
        test
      </div>
      <div class="cell-right">
        test
      </div>

    </div>
  </div>
</div>

这是 CSS:

*{
    box-sizing: border-box; 
}
div{
  border: 1px solid black;
}

.cell-left {
    height: 100%;
    padding: 5px;
    width: 50%;
    float: left;
    text-align:left
}

.cell-right {
    height: 100%;
    padding: 5px;
    width: 50%;

    float: left;
    text-align:right
}

.cell-bottom {
    height: 100%;
    padding: 5px;
    width: 94%;
    margin-left: 3%;
    float: left;
}

.cell-main {
    height: 100%;
    padding: 5px;
    width: 100%;
    float:left;
}

编辑:更新了 jsfiddle 和标题。

最佳答案

我认为您正在搜索 overflow-wrap属性(property)。

The overflow-wrap CSS property specifies whether or not the browser should insert line breaks within words to prevent text from overflowing its content box. (Mozilla MDN)

这个属性可以有以下值,如果你需要它递归,全局值对你来说可能很有趣:

/* Keyword values */
overflow-wrap: normal;
overflow-wrap: break-word;

/* Global values */
overflow-wrap: inherit;
overflow-wrap: initial;
overflow-wrap: unset;

如果您想保持地 block 的高度,请在主 div 上使用 overflow: auto

查看我的代码片段!

*{
    box-sizing: border-box; 
}
div{
  border: 1px solid black;
  overflow-wrap: break-word;
}

.cell-left {
    height: 100%;
    padding: 5px;
    width: 50%;
    float: left;
    text-align:left
}

.cell-right {
    height: 100%;
    padding: 5px;
    width: 50%;

    float: left;
    text-align:right
}

.cell-bottom {
    height: 100%;
    padding: 5px;
    width: 94%;
    margin-left: 3%;
    float: left;
}

.cell-main {
    height: 100%;
    padding: 5px;
    width: 100%;
    float:left;
}
<div class="cell-main">
  <div class="cell-left">
    testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttestte
  </div>
  <div class="cell-right">
    test
  </div>
  <div class="cell-bottom">
    <div class="cell-left">
      test
    </div>
    <div class="cell-right">
      test
    </div>
    <div class="cell-bottom">

      <div class="cell-left">
        test
      </div>
      <div class="cell-right">
        test
      </div>

    </div>
  </div>
</div>

关于html - CSS Float 水平溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47745185/

相关文章:

perl - 阶乘递归达到零时出错

javascript - 停止递归setTimeout函数

html - 如何使用 css nth-child(-n+3) 仅显示列表中的前三个图像

html - 对齐中心div

javascript - 无法诊断 : Background position different on page open

javascript - 在边界框内拖动和缩放图像

javascript - Angular:如何在列宽变化时隐藏/显示元素并更改弹出窗口的数据?

python - bs4 中的 get_text() 对于 span 标签有不同吗?无法删除跨度标签

html - css 框阴影,当父 div 有背景时不起作用

Java 中的 java.util.Random 和递归