【问题标题】:Flexbox overflow not expanding parent container in ChromeFlexbox溢出未在Chrome中扩展父容器
【发布时间】:2017-09-25 17:50:34
【问题描述】:

我使用 Flexbox 构建了一个树视图,但我无法让布局在 Chrome 中工作。溢出不起作用并破坏布局。

在 Firefox/IE/Edge 中,下面的代码 sn-p 可以正常工作,但溢出。

它在 Firefox 中运行的屏幕:

但在 Chrome 中,它会显示为这里的代码 sn-p。如何让溢出像在 FF/IE 中一样工作?

/* WorkPackage Treeview */

.flex-tree,
.flex-tree2,
.flex-tree-content,
.flex-tree-content2,
.flex-tree-bottom,
.flex-tree-parent,
.flex-tree-children,
.flex-tree-child-button {
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
}

.flex-tree,
.flex-tree2,
.flex-tree-content,
.flex-tree-content2,
.flex-tree-parent {
  -webkit-flex-direction: column;
  -ms-flex-direction: column;
  flex-direction: column;
}

.flex-tree {
  min-width: 240px;
  max-width: 245px;
  min-height: 180px;
  max-height: 180px;
  position: absolute;
  border-style: solid;
  border-width: 1px;
  z-index: 100;
}

.flex-tree2 {
  min-width: 240px;
  max-width: 245px;
  min-height: 380px;
  max-height: 380px;
  position: absolute;
  border-style: solid;
  border-width: 1px;
  z-index: 100;
}

.flex-tree-content {
  min-height: 150px;
  max-height: 150px;
  background-color: White;
  border-bottom-style: solid;
  border-bottom-width: 1px;
  overflow-y: scroll;
}

.flex-tree-content2 {
  min-height: 350px;
  max-height: 350px;
  background-color: White;
  border-bottom-style: solid;
  border-bottom-width: 1px;
  overflow-y: scroll;
}

.flex-tree-bottom {
  align-items: center;
  justify-content: center;
  min-height: 30px;
  max-height: 32px;
  background-color: Gray;
  border-bottom-style: solid;
  border-bottom-width: 1px;
}

.flex-tree-parent {
  margin-left: 20px;
}

.flex-tree-parent>.flex-tree-children:first-child {
  margin-left: 7px;
}

.flex-tree-children {
  -webkit-flex-direction: row-reverse;
  -ms-flex-direction: row-reverse;
  flex-direction: row-reverse;
  margin: 3px;
  margin-left: 27px;
  min-width: 101px;
  max-width: 101px;
  min-height: 20px;
  min-height: 20px;
}

.flex-tree-content>.flex-tree-children:first-child {
  margin-top: 15px;
  margin-left: 7px;
}

.flex-tree-content2>.flex-tree-children:first-child {
  margin-top: 15px;
  margin-left: 7px;
}

.flex-tree-child-button {
  width: 16px;
  height: 16px;
  background-image: url('https://cdn2.iconfinder.com/data/icons/bwpx/icons/toggle_minus.gif');
  background-repeat: no-repeat;
  cursor: pointer;
  order: 2;
}

.flex-tree-child {
  text-align: center;
  width: 80px;
  height: 20px;
  background-color: GreenYellow;
  border-style: solid;
  border-width: 1px;
  color: black;
  margin-left: 5px;
  order: 1;
}

.flex-tree-close {
  line-height: 7px;
  width: 75px;
  height: 25px;
  cursor: pointer;
  margin: 3px;
}
<div class="flex-tree" style="left: 50px; top: 50px;">
  <div class="flex-tree-content">
    <div class="flex-tree-children" id="2">
      <div class="flex-tree-child-button" id="2"></div><a class="flex-tree-child" id="2">1</a></div>
    <div class="flex-tree-children" id="6"><a class="flex-tree-child" id="6">1,1</a></div>
    <div class="flex-tree-parent" id="8">
      <div class="flex-tree-children" id="8">
        <div class="flex-tree-child-button" id="8"></div><a class="flex-tree-child" id="8">1,2</a></div>
      <div class="flex-tree-parent" id="19">
        <div class="flex-tree-children" id="19">
          <div class="flex-tree-child-button" id="19"></div><a class="flex-tree-child" id="19">1,2,1</a></div>
        <div class="flex-tree-children" id="26">
          <a class="flex-tree-child" id="26">1,2,1,1</a></div>


      </div>
      <div class="flex-tree-children" id="29"><a class="flex-tree-child" id="29">1,2,2</a></div>
      <div class="flex-tree-children" id="30"><a class="flex-tree-child" id="30">1,2,3</a></div>
    </div>
    <div class="flex-tree-children" id="9"><a class="flex-tree-child" id="9">1,3</a></div>
    <div class="flex-tree-children" id="23"><a class="flex-tree-child" id="23">1,4</a></div>
    <div class="flex-tree-children" id="24"><a class="flex-tree-child" id="24">New task</a></div>
  </div>
  <div class="flex-tree-bottom">
    <button class="flex-tree-close">Close</button>
  </div>
</div>

<div class="flex-tree2" style="left: 400px; top: 50px;">
  <div class="flex-tree-content2">
    <div class="flex-tree-children" id="2">
      <div class="flex-tree-child-button" id="2"></div><a class="flex-tree-child" id="2">1</a></div>
    <div class="flex-tree-children" id="6"><a class="flex-tree-child" id="6">1,1</a></div>
    <div class="flex-tree-parent" id="8">
      <div class="flex-tree-children" id="8">
        <div class="flex-tree-child-button" id="8"></div><a class="flex-tree-child" id="8">1,2</a></div>
      <div class="flex-tree-parent" id="19">
        <div class="flex-tree-children" id="19">
          <div class="flex-tree-child-button" id="19"></div><a class="flex-tree-child" id="19">1,2,1</a></div>
        <div class="flex-tree-children" id="26">
          <a class="flex-tree-child" id="26">1,2,1,1</a></div>


      </div>
      <div class="flex-tree-children" id="29"><a class="flex-tree-child" id="29">1,2,2</a></div>
      <div class="flex-tree-children" id="30"><a class="flex-tree-child" id="30">1,2,3</a></div>
    </div>
    <div class="flex-tree-children" id="9"><a class="flex-tree-child" id="9">1,3</a></div>
    <div class="flex-tree-children" id="23"><a class="flex-tree-child" id="23">1,4</a></div>
    <div class="flex-tree-children" id="24"><a class="flex-tree-child" id="24">New task</a></div>
  </div>
  <div class="flex-tree-bottom">
    <button class="flex-tree-close">Close</button>
  </div>
</div>

【问题讨论】:

    标签: html css flexbox overflow


    【解决方案1】:

    .flex-tree-parent 上使用flex-shrink: 0

    /* WorkPackage Treeview */
    
    .flex-tree,
    .flex-tree2,
    .flex-tree-content,
    .flex-tree-content2,
    .flex-tree-bottom,
    .flex-tree-parent,
    .flex-tree-children,
    .flex-tree-child-button {
      display: -ms-flexbox;
      display: -webkit-flex;
      display: flex;
    }
    
    .flex-tree,
    .flex-tree2,
    .flex-tree-content,
    .flex-tree-content2,
    .flex-tree-parent {
      -webkit-flex-direction: column;
      -ms-flex-direction: column;
      flex-direction: column;
    }
    
    .flex-tree {
      min-width: 240px;
      max-width: 245px;
      min-height: 180px;
      max-height: 180px;
      position: absolute;
      border-style: solid;
      border-width: 1px;
      z-index: 100;
    }
    
    .flex-tree2 {
      min-width: 240px;
      max-width: 245px;
      min-height: 380px;
      max-height: 380px;
      position: absolute;
      border-style: solid;
      border-width: 1px;
      z-index: 100;
    }
    
    .flex-tree-content {
      min-height: 150px;
      max-height: 150px;
      background-color: White;
      border-bottom-style: solid;
      border-bottom-width: 1px;
      overflow-y: scroll;
    }
    
    .flex-tree-content2 {
      min-height: 350px;
      max-height: 350px;
      background-color: White;
      border-bottom-style: solid;
      border-bottom-width: 1px;
      overflow-y: scroll;
    }
    
    .flex-tree-bottom {
      align-items: center;
      justify-content: center;
      min-height: 30px;
      max-height: 32px;
      background-color: Gray;
      border-bottom-style: solid;
      border-bottom-width: 1px;
    }
    
    .flex-tree-parent {
      margin-left: 20px;
      flex-shrink: 0;
    }
    
    .flex-tree-parent>.flex-tree-children:first-child {
      margin-left: 7px;
    }
    
    .flex-tree-children {
      -webkit-flex-direction: row-reverse;
      -ms-flex-direction: row-reverse;
      flex-direction: row-reverse;
      margin: 3px;
      margin-left: 27px;
      min-width: 101px;
      max-width: 101px;
      min-height: 20px;
      min-height: 20px;
    }
    
    .flex-tree-content>.flex-tree-children:first-child {
      margin-top: 15px;
      margin-left: 7px;
    }
    
    .flex-tree-content2>.flex-tree-children:first-child {
      margin-top: 15px;
      margin-left: 7px;
    }
    
    .flex-tree-child-button {
      width: 16px;
      height: 16px;
      background-image: url('https://cdn2.iconfinder.com/data/icons/bwpx/icons/toggle_minus.gif');
      background-repeat: no-repeat;
      cursor: pointer;
      order: 2;
    }
    
    .flex-tree-child {
      text-align: center;
      width: 80px;
      height: 20px;
      background-color: GreenYellow;
      border-style: solid;
      border-width: 1px;
      color: black;
      margin-left: 5px;
      order: 1;
    }
    
    .flex-tree-close {
      line-height: 7px;
      width: 75px;
      height: 25px;
      cursor: pointer;
      margin: 3px;
    }
    <div class="flex-tree" style="left: 50px; top: 50px;">
      <div class="flex-tree-content">
        <div class="flex-tree-children" id="2">
          <div class="flex-tree-child-button" id="2"></div><a class="flex-tree-child" id="2">1</a></div>
        <div class="flex-tree-children" id="6"><a class="flex-tree-child" id="6">1,1</a></div>
        <div class="flex-tree-parent" id="8">
          <div class="flex-tree-children" id="8">
            <div class="flex-tree-child-button" id="8"></div><a class="flex-tree-child" id="8">1,2</a></div>
          <div class="flex-tree-parent" id="19">
            <div class="flex-tree-children" id="19">
              <div class="flex-tree-child-button" id="19"></div><a class="flex-tree-child" id="19">1,2,1</a></div>
            <div class="flex-tree-children" id="26">
              <a class="flex-tree-child" id="26">1,2,1,1</a></div>
    
    
          </div>
          <div class="flex-tree-children" id="29"><a class="flex-tree-child" id="29">1,2,2</a></div>
          <div class="flex-tree-children" id="30"><a class="flex-tree-child" id="30">1,2,3</a></div>
        </div>
        <div class="flex-tree-children" id="9"><a class="flex-tree-child" id="9">1,3</a></div>
        <div class="flex-tree-children" id="23"><a class="flex-tree-child" id="23">1,4</a></div>
        <div class="flex-tree-children" id="24"><a class="flex-tree-child" id="24">New task</a></div>
      </div>
      <div class="flex-tree-bottom">
        <button class="flex-tree-close">Close</button>
      </div>
    </div>
    
    <div class="flex-tree2" style="left: 400px; top: 50px;">
      <div class="flex-tree-content2">
        <div class="flex-tree-children" id="2">
          <div class="flex-tree-child-button" id="2"></div><a class="flex-tree-child" id="2">1</a></div>
        <div class="flex-tree-children" id="6"><a class="flex-tree-child" id="6">1,1</a></div>
        <div class="flex-tree-parent" id="8">
          <div class="flex-tree-children" id="8">
            <div class="flex-tree-child-button" id="8"></div><a class="flex-tree-child" id="8">1,2</a></div>
          <div class="flex-tree-parent" id="19">
            <div class="flex-tree-children" id="19">
              <div class="flex-tree-child-button" id="19"></div><a class="flex-tree-child" id="19">1,2,1</a></div>
            <div class="flex-tree-children" id="26">
              <a class="flex-tree-child" id="26">1,2,1,1</a></div>
    
    
          </div>
          <div class="flex-tree-children" id="29"><a class="flex-tree-child" id="29">1,2,2</a></div>
          <div class="flex-tree-children" id="30"><a class="flex-tree-child" id="30">1,2,3</a></div>
        </div>
        <div class="flex-tree-children" id="9"><a class="flex-tree-child" id="9">1,3</a></div>
        <div class="flex-tree-children" id="23"><a class="flex-tree-child" id="23">1,4</a></div>
        <div class="flex-tree-children" id="24"><a class="flex-tree-child" id="24">New task</a></div>
      </div>
      <div class="flex-tree-bottom">
        <button class="flex-tree-close">Close</button>
      </div>
    </div>

    【讨论】:

    • 感谢您的快速帮助,我尝试了所有的增长但没有想到收缩:)
    猜你喜欢
    • 2016-06-10
    • 2022-12-07
    • 1970-01-01
    • 2016-08-18
    • 1970-01-01
    • 2014-05-28
    • 2019-03-01
    • 2023-04-10
    • 2017-08-25
    相关资源
    最近更新 更多