Search code examples
cssflexboxinternet-explorer-10

Flex - three columns, the 3d one goes beyond the screen


When running this code, the right column goes long beyond the screen, rightward.

  1. I want the side columns to be responsive, while the middle one to be with a fixed width.

  2. And how to make it working in IE10?

Layout:

<div class="wrapper">
    <div class="left"></div>
    <div class="middle">
        <div>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin eget ante bibendum, cursus diam sit amet
        </div>
    </div>
    <div class="right"></div>
</div>

CSS:

.wrapper {
  height: 80px;
  width: 100%;
  display: -webkit-flex;
  display: flex;
  -webkit-flex-direction: row;
  flex-direction: row;
  -webkit-align-items: center;
  align-items: center;
  -webkit-justify-content: center;
  justify-content: center;
}
.wrapper .left {
  height: 100%;
  flex: 0 0 100%;
  background-color: yellow;
}
.wrapper .middle {
  height: 100%;
  flex: 0 0 800px;
  background-color: orange;
}
.wrapper .right {
  height: 100%;
  flex: 0 0 100%;
  background-color: red;
}

Solution

  • You're not using the flex shorthand properly. This is the correct format: flex: <flex-grow> <flex-shrink>? || <flex-basis> ;

    Ive changed yours to work with your specifications including IE. Because of the 800ox fixed width you'll need to view this in full screen.

    .wrapper {
      height: 80px;
      width: 100%;
      display: -webkit-box;
      display: -ms-flexbox;
      display: flex;
      -webkit-box-orient: horizontal;
      -webkit-box-direction: normal;
      -ms-flex-direction: row;
      flex-direction: row;
      -webkit-box-align: center;
      -ms-flex-align: center;
      align-items: center;
      -webkit-box-pack: center;
      -ms-flex-pack: center;
      justify-content: center;
    }
    .wrapper .left {
      height: 100%;
      -webkit-box-flex: 1;
      -ms-flex: 1 1 0%;
      flex: 1 1 0%;
      background-color: yellow;
    }
    .wrapper .middle {
      height: 100%;
      width: 800px;
      background-color: orange;
    }
    .wrapper .right {
      height: 100%;
      -webkit-box-flex: 1;
      -ms-flex: 1 1 0%;
      flex: 1 1 0%;
      background-color: red;
    }
    <div class="wrapper">
      <div class="left"></div>
      <div class="middle">
        <div>
          Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin eget ante bibendum, cursus diam sit amet
        </div>
      </div>
      <div class="right"></div>
    </div>