1

In the code below the paragraphs are not getting wrapped on small screen while using Internet Explorer 11. By searching for solutions I found that if flex-basis:100% or width:100% is applied on .fix div then the paragraphs get wrapped but this method breaks my layout. What can be the possible solution that will

  1. Keep my layout intact
  2. The paragraphs will get wrapped on small screen

Output of the Internet Explorer 11:

Internet Explorer flexbox bug example

.container-1 {
  display: flex;
  justify-content: flex-end;
  border: 1px solid red;
  
}

.container-2 {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  border: 1px solid blue;
}
<div class='container-1'>
  <div class='fix'>
    <div class='container-2'>
      <p>Center Aligned Content</p>
      <p>Some content goes here. Some content goes here. Some content goes here. </p>
    </div>
  </div>
</div>
Mirajul Momin
  • 157
  • 1
  • 17

3 Answers3

3

You're running up against a couple of problems involving flex and/or IE11.

Try this:

.container-1 {
  display: flex;
  justify-content: flex-end;
  border: 1px solid red;
}

.fix {
  display: flex;
}

.container-2 {
  width: 100%;
  display: flex;
  flex-direction: column;
  text-align: center;
  border: 1px solid blue;
}
<div class='container-1'>
  <div class='fix'>
    <div class='container-2'>
      <p>Center Aligned Content</p>
      <p>Some content goes here. Some content goes here. Some content goes here. </p>
    </div>
  </div>
</div>

Here's an explanation of the problems:

Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
1

I think we can automatically set the fix width. We need to use JavaScript to set it. If the window is resized to a size that container-1 width is the same as container-2 width, then we can set the fix width to 100%. If we resize back, then we remove the fix width.

For the working demo, you could refer to the sample below which has been tested in IE 11:

var c1 = document.getElementsByClassName('container-1')[0];
var c2 = document.getElementsByClassName('container-2')[0];
var fix = document.getElementsByClassName('fix')[0];
document.getElementById('c2').innerText = c2.offsetWidth;
var c2width = parseFloat(document.getElementById('c2').innerText);

function setStyle() {
  if (c1.offsetWidth <= c2.offsetWidth) {
    fix.style.width = '100%';
  }
  if (c2.offsetWidth > c2width) {
    fix.style.width = '';
  }
}

window.onresize = setStyle;
.container-1 {
  display: flex;
  justify-content: flex-end;
  border: 1px solid red;
}

.container-2 {
  display: flex;
  flex-direction: column;
  text-align: center;
  border: 1px solid blue;
}
<div class='container-1'>
  <div class='fix'>
    <div class='container-2'>
      <p>Center Aligned Content</p>
      <p>Some content goes here. Some content goes here. Some content goes here. </p>
    </div>
  </div>
</div>
<div id="c2" style="display:none"></div>

The result in IE 11 is like below:

enter image description here

Yu Zhou
  • 11,532
  • 1
  • 8
  • 22
0

After long research I found that if .fix div has overflow:hidden style then the problem is solved.

.container-1 {
  display: flex;
  justify-content: flex-end;
  border: 1px solid red;
}

.fix {
  overflow: hidden;
}

.container-2 {
  display: flex;
  flex-direction: column;
  text-align: center;
  border: 1px solid blue;
}
<div class='container-1'>
  <div class='fix'>
    <div class='container-2'>
      <p>Center Aligned Content</p>
      <p>Some content goes here. Some content goes here. Some content goes here. </p>
    </div>
  </div>
</div>
Mirajul Momin
  • 157
  • 1
  • 17