【问题标题】:Overflow hidden on a child of a flex child [duplicate]隐藏在弹性孩子的孩子身上的溢出[重复]
【发布时间】:2020-02-20 11:49:55
【问题描述】:

我有一个带有flex: 1 的弹性元素。它是一个列,并且应该占用与兄弟相同的空间

此列有两个子列。一个允许溢出,另一个不允许溢出。 如何仅在一个孩子上定义overflow: hidden

.row {
  display: flex;
  justify-content: space-between;
}

.col {
  background-color: blue;
  border: 1px solid white;
  padding: 10px;
  flex: 1;
  position: relative;
  
  &:hover {
    .child-that-can-overflow {
      display: block;
    }
  }
}

.child-that-can-overflow {
  position: absolute;
  right: -20px;
  left: 0;
  background-color: yellow;
  z-index: 100;
  display: none;
}

.child-that-cant-overflow {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}
<div class="row">
  <div class="col">
    <div class="child-that-cant-overflow">
      long long text that causes overflow. It should be hidden, with text ellipsis
    </div>
    
    <div class="child-that-can-overflow">
      BUTTON
    </div>
  </div>
  <div class="col"></div>
  <div class="col"></div>

</div>

如果我将父级设置为overflow: hidden,我的按钮将被剪切。如果我不这样做,另一个孩子的文本会导致列溢出。

有什么创意解决方案吗?
谢谢!

JSFiddle

【问题讨论】:

  • 按钮和文本是您的子元素,您需要段落来溢出按钮按钮吗?我说的对吗?
  • 我不太明白这个问题。我需要 BUTTON 能够溢出它的父级(col)并且隐藏文本的溢出(IE - 不扩展父级)
  • min-width: 0 添加到.coljsfiddle.net/netfp7Lr

标签: html css flexbox overflow


【解决方案1】:

试试这个

.col {
  background-color: blue;
  border: 1px solid white;
  padding: 10px;
  flex: 1;
  position: relative;
  height: 20px;//as your requirement
    overflow: auto;// to auto scroll

  &:hover {
    .child-that-can-overflow {
      display: block;
    }
  }
}

【讨论】:

    猜你喜欢
    • 2021-06-10
    • 1970-01-01
    • 2019-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-24
    • 1970-01-01
    • 2014-11-21
    相关资源
    最近更新 更多