CSS prevent div flex from stretching child

前端 未结 2 658
伪装坚强ぢ
伪装坚强ぢ 2020-12-11 09:58

The moment div has the flex display property it stretches the paragraph. I seem to be missing something but no property I can think to put on the flex div chang

相关标签:
2条回答
  • 2020-12-11 10:13

    add another wrapper:

    div {
      display: flex;
      justify-content: center;
      flex-direction: column;
      text-align:center;
      height: 200px;
      width: 100px;
    }
    
    p span{
      background-color: green;
    }
    <div>
      <p>
        <span>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod</span>
      </p>
    </div>

    Related question to understand why your inline is ignored:

    Are flex items a block level element?

    Usage of display property of flex box items

    0 讨论(0)
  • 2020-12-11 10:15

    span { 
      -webkit-box-decoration-break: clone;
      -o-box-decoration-break: clone;
      box-decoration-break: clone;
      background-color: green;
    }
    div {
      text-align:center;
      height: 200px;
      width: 100px;
    }
    <div>
      <span>
        Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
      </span>
    </div

    0 讨论(0)
提交回复
热议问题