Text in a flex container doesn't wrap in IE11

后端 未结 12 1992
自闭症患者
自闭症患者 2020-11-22 05:23

Consider the following snippet:

相关标签:
12条回答
  • 2020-11-22 05:40
    .grandparent{
       display: table;
    }
    
    .parent{
      display: table-cell
      vertical-align: middle
    }
    

    This worked for me.

    0 讨论(0)
  • 2020-11-22 05:43

    Me too I encountered this issue.

    The only alternative is to define a width (or max-width) in the child elements. IE 11 is a bit stupid, and me I just spent 20 minutes to realize this solution.

    .parent {
      display: flex;
      flex-direction: column;
      width: 800px;
      border: 1px solid red;
      align-items: center;
    }
    .child {
      border: 1px solid blue;
      max-width: 800px;
      @media (max-width:960px){ // <--- Here we go. The text won't wrap ? we will make it break !
        max-width: 600px;
      }
      @media (max-width:600px){
        max-width: 400px;
      }
      @media (max-width:400px){
        max-width: 150px;
      }
    }
    
    <div class="parent">
      <div class="child">
        Lorem Ipsum is simply dummy text of the printing and typesetting industry
      </div>
      <div class="child">
        Lorem Ipsum is simply dummy text of the printing and typesetting industry
      </div>
    </div>
    
    0 讨论(0)
  • 2020-11-22 05:43

    Why use a complicated solution if a simple one works too?

    .child {
      white-space: normal;
    }
    
    0 讨论(0)
  • 2020-11-22 05:46

    Add this to your code:

    .child { width: 100%; }
    

    We know that a block-level child is supposed to occupy the full width of the parent.

    Chrome understands this.

    IE11, for whatever reason, wants an explicit request.

    Using flex-basis: 100% or flex: 1 also works.

    .parent {
      display: flex;
      flex-direction: column;
      width: 400px;
      border: 1px solid red;
      align-items: center;
    }
    .child {
      border: 1px solid blue;
      width: calc(100% - 2px);       /* NEW; used calc to adjust for parent borders */
    }
    <div class="parent">
      <div class="child">
        Lorem Ipsum is simply dummy text of the printing and typesetting industry
      </div>
      <div class="child">
        Lorem Ipsum is simply dummy text of the printing and typesetting industry
      </div>
    </div>

    Note: Sometimes it will be necessary to sort through the various levels of the HTML structure to pinpoint which container gets the width: 100%. CSS wrap text not working in IE

    0 讨论(0)
  • Somehow all these solutions didn't work for me. There is clearly an IE bug in flex-direction:column.

    I only got it working after removing flex-direction:

    flex-wrap: wrap;
    align-items: center;
    align-content: center;
    
    0 讨论(0)
  • 2020-11-22 05:57

    I did not find my solution here, maybe someone will be useful:

    .child-with-overflowed-text{
      word-wrap: break-all;
    }
    

    Good luck!

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