1

My aim is to have to 2 columns with vertical centered content. One is only a dynamic image - that needs to be restricted to its div - one is only text. No Overflow is allowed also.

my code runs without a problem in Chrome but Firefox sets the image size much too high and I have no slightest clue why it does that.

Hope anyone can help me figure this out. Already wasted hours on this problem.

Thank you guys!

jsFiddle

html {
  height: 100%;
}

body {
  width: 100%;
  height: 100%;
  margin: 0px;
  padding: 0px;
  overflow: hidden;
}

.Grid {
  display: -webkit-box;
  /* OLD - iOS 6-, Safari 3.1-6 */
  display: -moz-box;
  /* OLD - Firefox 19- (buggy but mostly works) */
  display: -ms-flexbox;
  /* TWEENER - IE 10 */
  display: -webkit-flex;
  /* NEW - Chrome */
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: row;
}

.Grid-cell {
  flex: 1;
  -webkit-flex: 1;
  -moz-box-flex: 1;
  -ms-flexbox: 1;
  -moz-box: 1;
}

.Grid--top {
  align-items: flex-start;
  height: 90%;
}

.Grid-cell--center {
  align-self: center;
}

.Grid-cell--image {
  text-align: center;
  max-height: 100%;
}

.u-1of3,
.u-2of3 {
  -webkit-flex: 0;
  -moz-box-flex: 0;
  flex: 0 0 auto;
}

.u-1of3 {
  width: 35%;
}

.productImages {
  height: 80%;
}
<body>
  <div class="Grid Grid--top">
    <div class="Grid-cell Grid-cell--center Grid-cell--image">
      <div id="productImages">
        <img id="productImage0" class="productImages" src="http://placehold.it/450x1550" />
      </div>
    </div>
    <div class="Grid-cell Grid-cell--center u-1of3">
      2. Section
    </div>
  </div>
</body>
Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
a1xon
  • 85
  • 1
  • 1
  • 6

1 Answers1

1

The main problem appears to be your use of percentage heights.

Different browsers render percentage heights differently, depending on whether the parent element has a defined height or not.

Often, the max-height and min-height properties don't work well with percentage heights applied to elements further in the DOM.

With a few adjustments to the percentage heights in your code, the layout appears to work.

html {
  height: 100%;
}

body {
  height: 100%;
  margin: 0px;
  padding: 0px;
}

.Grid {
  display: flex;
  align-items: center;
  justify-content: center;
}

.Grid-cell {
  flex: 1;
}

.Grid--top {
  align-items: flex-start;
  height: 100%;
}

.Grid-cell--center {
  align-self: center;
}

.Grid-cell--image {
  text-align: center;
  height: 100%;
}

.u-1of3, .u-2of3 {
  flex: 0 0 auto;
}

.u-1of3 {
  width: 35%;
}

#productImages {
  height: 100%;
}

.productImages {
  max-height: 100%;
}
<div class="Grid Grid--top">
  <div class="Grid-cell Grid-cell--center Grid-cell--image">
    <div id="productImages">
      <img id="productImage0" class="productImages" src="http://placehold.it/450x1550" />
    </div>
  </div>
  <div class="Grid-cell Grid-cell--center u-1of3">
    2. Section
  </div>
</div>

revised fiddle

Here's a simplified version that may also work for you:

.Grid {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

.productImages {
  max-height: 100vh;
}

body {
  margin: 0px;
}

* {
  box-sizing: border-box;
}
<div class="Grid Grid--top">
  <div class="Grid-cell Grid-cell--center Grid-cell--image">
    <div id="productImages">
      <img id="productImage0" class="productImages" src="http://placehold.it/450x1550" />
    </div>
  </div>
  <div class="Grid-cell Grid-cell--center u-1of3">
    2. Section
  </div>
</div>

revised fiddle

More information:

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