cdv
cdv

Reputation: 85

Flexbox centering not working in IE 11

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>

Upvotes: 2

Views: 5419

Answers (1)

CodeSpent
CodeSpent

Reputation: 1904

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;
}

Upvotes: 6

Related Questions