Why is an element with width:100% not taking the parent's width?

前端 未结 3 668
失恋的感觉
失恋的感觉 2021-01-14 15:45

I am facing the issue that I cannot set the same width as its parent inside a flexbox item.

Here is the code and the span with the class theSpan doesn\'

3条回答
  •  隐瞒了意图╮
    2021-01-14 16:19

    You should turn the span into block via display.

    .container {
      display: flex;
    }
    .item1 {
      flex: 1 1 200px;
      border: 5px solid yellow;
    }
    .item2 {
      flex: 1 1 200px;
      border: 5px solid blue;
    }
    .item3 {
      flex: 1 1 200px;
      border: 5px solid red;
    }
    .theSpan {
      display:block;/* <= display instead or with width will do */
      border: 2px solid black;
    }
    abcdefg
    1
    2

提交回复
热议问题