Vertical centering with stacked flexboxes is malfunctioning in Chrome

There is an issue with the following code snippet in Google Chrome:

<div class="flex-container">
    <div class="flex-item">
      <div>
        <div>
           <h2>This is a test</h2>
        </div>
       </div>
    </div>
    <div class="flex-item">
      <div>
        <div>
           <h2>This is a test</h2>
        </div>
       </div>
    </div>
    <div class="flex-item">
      <div>
        <div>
           <h2>This is a test</h2>
        </div>
       </div>
    </div>
</div>

This problem is specific to SCSS styling:

body,html {
  height:100%;
  background:#1D1F20;
  font-family:sans-serif;
  color:#fff;
}
.flex-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  height:100%;
  .flex-item {
    flex: 1 1 auto;
    align-self: center;
    background:#87BEB7;
    padding:0 10px;
    &:nth-child(2) {
      background:#ADBEBC;
    }
    &:nth-child(3) {
      background:#BE8A74;
    }
    > div {
      display: flex;
      justify-content: center;
      align-items: flex-start;
      height:100%; // This seems to be the issue
      div {
        flex: 0 1 auto;
        align-self: center;
        background:#5C726F;
        padding:10px
      }
    }
  }
}

The expected behavior is for the second flexbox-container (.flex-item > div) to have the full height of the flex-child (.flex-item), but it doesn't work properly in Chrome.

A workaround using position absolute exists, but it's not preferred.

Codepen: http://codepen.io/anon/pen/QwpzLX

To see the desired result, open the code in Firefox, and to see the current situation, open it in Chrome.

Any suggestions or help would be greatly appreciated.

Answer №1

Check out the scss code that is currently working:

.flex-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    height:100%;
    .flex-item {
        flex: 1 1 auto;
        align-self: center;
        background:#87BEB7;
        padding:0 10px;
        display: flex;

        &:nth-child(2) {
            background:#ADBEBC;
        }
        &:nth-child(3) {
            background:#BE8A74;
        }
        > div {
            display: flex;
            justify-content: center;
            align-items: flex-start;

            div {
                flex: 0 1 auto;
                align-self: center;
                background:#5C726F;
                padding:10px
            }
        }
    }
}

To make it work, remember to add display:flex; to .flex-item and delete height: 100%.

If you want to see a demo, click here: http://jsfiddle.net/omgL91r8/1/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

My DIV elements are not responding to the widths I set for them. What could be the issue?

Recently, I've been delving into the world of Flex to experiment with some unique layouts. However, I encountered an issue where my divs were not recognizing widths as expected. I attempted to set the first div of each row to 5% width so they would ...

Create a seamless typing effect in JavaScript that loops indefinitely

I've managed to tweak this code I stumbled upon to almost perfectly fit my needs, except for one thing - it keeps looping. I just want it to type "zero", delete it, and then type "one" before stopping. I've tried making some adjustments here and ...

The background-clip property in CSS3 is failing to apply to borders with a transparent

I am currently learning how to create transparent borders by following the tutorial on CSS-Tricks website. Unfortunately, my code is not producing the desired transparent border effect. I have double-checked my code and everything seems correct to me. For ...

Creating a personalized input slider: A step-by-step guide

I have a question about how to design a custom input slider with the label inside the field itself. The desired output should look like the screenshot below: https://i.sstatic.net/gE6EJ.png I have successfully created the input field part, but I am stru ...

Two CSS borders of varying heights

Just wondering, can we achieve something similar to the style shown in the attachment using only CSS? <h3 style="border-bottom:1px solid #515151"><span style="border-bottom:3px solid #0066b3">HEADER</span></h3> ...

Tips for making an input field that overlays text

I am currently working on a project that involves creating multiple cards using Bootstrap. Each card consists of a header, body, and footer. When a card is clicked on, I want an input field to appear in the header, footer, and body sections, overlaying the ...

What are the best scenarios for using %, em, or ex units in CSS font styles?

I'm trying to figure out in what situations I should use %, em, and ex as font units of measurement in CSS. Can someone provide some clarity on this for me? I'm feeling a bit confused. ...

Tips on enlarging a webpage without showing the scroll bar on the main component

My goal is to create a webpage that resembles a window application. However, I've encountered an issue where zooming in on the page results in a scroll bar appearing on the main page. The parameters for the main page (the parent) are set as follows: w ...

What is the method to align my text to the top of the page?

I'm working on a 4-column page and trying to insert content. Everything is functioning properly except for getting my first div to align to the top in inline-blocks. As a newbie, I feel like I must be overlooking something simple. (I've tried usi ...

Getting Your Content Centered Horizontally with Fixed Positioning in CSS

I would like the div to be centered horizontally with a fixed position, but it doesn't seem to work in my code. Can someone help me troubleshoot? Check out the demo here. HTML: <div id="fancybox-thumbs" class="bottom" style="width: 675px;"> ...

Issue with undefined Sass variable when using Global Sass variable in Vue 3 with Vite: [sass] Undefined variable error

https://i.sstatic.net/7K0uF.png Greetings! I have embarked on the journey of migrating a Vue application from Webpack to Vite. To kick things off, I am starting with a small project. However, I seem to be encountering an error: '[sass] Undefined var ...

Customize the background color of a particular select element within an array of dynamically created select elements

I've been experimenting with jQuery to dynamically adjust the background color of a select element based on the chosen option. The select elements are being generated using the following code: while ($qrow = $qquery->fetch(PDO::FETCH_ASSOC)) { ...

Transitioning Wordpress menu layout from horizontal to vertical

On several websites with the same template and content but different locations, only one site is experiencing menu display issues. I have attempted deleting and re-adding the menu, as well as copying it from another working site, but the problem persists. ...

Problem with image title in jQuery mobile

My code seems to be having an issue where the title does not display completely when hovering over it. For example, if the title is set as "The Value", only "The" is shown and not "The Value". Can anyone help me identify the mistake? Thank you in advance ...

What could be the reason for foundations occasionally failing to size columns equally?

Check out this foundation JSFiddle I created: http://jsfiddle.net/nycynik/qn8z3cut/2/ When I view it, the layout doesn't resemble tic-tac-toe at all. The right column is aligned to the right, and the sizes of the other columns are all different. I wa ...

Ways to automatically close the dropdown button when the user clicks outside of it

Is there a way to automatically close the dropdown button when a user clicks outside of it? Check out this link for possible solutions ...

The alignment of the text with the Bootstrap glyphicon is off

Currently, I am in the process of developing a form and implementing validation on my bootstrap form using bootstrap components. To handle server side validation, I am utilizing a c# class library, and then using c# code-behind to apply styles when the for ...

Unable to hyperlink in a div containing the my-auto class in Bootstrap

I am facing an issue with my carousel layout. I have 3 columns, and one column is reserved for Prev & Next carousel controls. These controls are vertically aligned using the my-auto class. However, after adding this class to the column, the links within it ...

What is the best way to create a floating navigation bar that appears when I tap on an icon?

As a beginner in the realm of React, I recently explored a tutorial on creating a navigation bar. Following the guidance, I successfully implemented a sidebar-style navbar that appears when the menu icon is clicked for smaller screen sizes. To hide it, I u ...

The alignment of Material-UI Button and ButtonGroup is not consistent

I'm puzzled as to why the Button and ButtonGroup elements are not aligned on the baseline in the code snippet provided. Is there a specific property that can be adjusted on the ButtonGroup element to achieve alignment? <!DOCTYPE html> <htm ...