2

justify-content and align-items using center seems to not be working in IE 11. In other browsers it works just as I would expect. Does anybody know a workaround?

.box {
  align-items: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
}

.score-wrapper {
  align-items: center;
  display: flex;
  justify-content: center;
  min-height: 280px;
}

.overlay-circle {
  border-radius: 100px;
  border: 1px solid red;
  fill: transparent;
  height: 200px;
  position: absolute;
  width: 200px;
}

.center-circle {
  border-radius: 90px;
  border: 1px solid blue;
  height: 180px;
  position: absolute;
  width: 180px;
}
<div class="box">
  <div class="score-wrapper">
    <div class="overlay-circle"></div>
    <div class="center-circle">
      <div class="score">
        <p>800</p>
        <p>Excellent</p>
      </div>
    </div>
  </div>
Andrzej Ziółek
  • 2,241
  • 1
  • 13
  • 21
cdv
  • 85
  • 2
  • 10
  • 1
    Possible duplicate of [Flexbox Not Centering Vertically in IE](https://stackoverflow.com/questions/19371626/flexbox-not-centering-vertically-in-ie) – M - Jul 06 '18 at 23:22

1 Answers1

6

Flexbox is pretty buggy when it comes to IE per CanIUse, 2 of which that are mentioned:

  • In IE10 and IE11, containers with display: flex and flex-direction: column will not properly calculate their flexed childrens' sizes if the container has min-height but no explicit height property. See bug.
  • IE 11 does not vertically align items correctly when min-height is used see bug

This being said, add explicit heights as a fallback on .score-wrapper for IE11.

.box {
  align-items: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
}

.score-wrapper {
  align-items: center;
  display: flex;
  justify-content: center;
  min-height: 280px;
  height: 280px;
}

.overlay-circle {
  border-radius: 100px;
  border: 1px solid red;
  fill: transparent;
  height: 200px;
  position: absolute;
  width: 200px;
}

.center-circle {
  border-radius: 90px;
  border: 1px solid blue;
  height: 180px;
  position: absolute;
  width: 180px;
}
CodeSpent
  • 1,684
  • 4
  • 23
  • 46
  • 1
    I'm still seeing the same result on IE 11. But it seems like I'm not supposed to use `absolute` positioning on flex children or else they won't be in the flex layout. – cdv Jul 06 '18 at 23:55
  • Yes and no. For the sake of designing shapes rules can be broken a bit since its hacky regardless. There are some redundancies I spot there, but let me take a better look. – CodeSpent Jul 06 '18 at 23:59