text-overflow: ellipsis not working in a nested flex container

前端 未结 2 1170
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-19 00:30

I have a component which consists of text next to a button. The text must shrink and get cut off if not enough space is available. Like this:

2条回答
  •  囚心锁ツ
    2020-12-19 00:52

    Use width property to work with overflow

    Note: Width should be in px

    .container .box {
      background-color: #efefef;
      padding: 5px;
      border: 1px solid #666666;
      flex: 0 0 auto;
    }
    .container .text {
      flex: 1 1 auto;
      width: 250px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .container {
      display: flex;
    }
    .main {
      display: flex;
    }
    .main .side {
      width: 100px;
      background-color: #ff9900;
      flex: 0 0 auto;
    }
    .main .content {
      flex: 1 1 auto;
    }
    This is a text that is supposed to get truncated properly when ndgsdgeeded.
    Hello

提交回复
热议问题