Chrome / Safari not filling 100% height of flex parent

Solution Use nested flex containers. Get rid of percentage heights. Get rid of table properties. Get rid of vertical-align. Avoid absolute positioning. Just stick with flexbox all the way through. Apply display: flex to the flex item (.item), making it a flex container. This automatically sets align-items: stretch, which tells the child (.item-inner) to expand … Read more

Make a div span two rows in a grid

You have fixed heights on your child elements (.block). Based on that information, we can extrapolate the height of the container (#wrapper). By knowing the height of the container, your layout can be achieved using CSS Flexbox with flex-direction: column and flex-wrap: wrap. A fixed height on the container serves as a breakpoint, telling flex … Read more

Targeting flex items on the last or specific row

Unfortunately, in the current iteration of flexbox (Level 1), there is no clean way to solve the last-row alignment problem. It’s a common problem. It would be useful to have a flex property along the lines of: last-row last-column only-child-in-a-row alone-in-a-column This problem does appear to be a high priority for Flexbox Level 2: CSS … Read more

Is it possible for flex items to align tightly to the items above them?

Flexbox is a “1-dimensional” layout system: It can align items along horizontal OR vertical lines. A true grid system is “2-dimensional”: It can align items along horizontal AND vertical lines. In other words, cells can span across columns and rows, which flexbox cannot do. This is why flexbox has a limited capacity for building grids. … Read more

Center one and right/left align other flexbox element

Below are five options for achieving this layout: CSS Positioning Flexbox with Invisible DOM Element Flexbox with Invisible Pseudo-Element Flexbox with flex: 1 CSS Grid Layout Method #1: CSS Positioning Properties Apply position: relative to the flex container. Apply position: absolute to item D. Now this item is absolutely positioned within the flex container. More … Read more

CSS-only masonry layout

2021 Update CSS Grid Layout Level 3 includes a masonry feature. Code will look like this: grid-template-rows: masonry grid-template-columns: masonry As of March 2021, it’s only available in Firefox (after activating the flag). https://drafts.csswg.org/css-grid-3/#masonry-layout https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout/Masonry_Layout end update; original answer below Flexbox A dynamic masonry layout is not possible with flexbox, at least not in a … Read more

In CSS Flexbox, why are there no “justify-items” and “justify-self” properties?

Methods for Aligning Flex Items along the Main Axis As stated in the question: To align flex items along the main axis there is one property: justify-content To align flex items along the cross axis there are three properties: align-content, align-items and align-self. The question then asks: Why are there no justify-items and justify-self properties? … Read more

Why don’t flex items shrink past content size?

The Automatic Minimum Size of Flex Items You’re encountering a flexbox default setting. A flex item cannot be smaller than the size of its content along the main axis. The defaults are… min-width: auto min-height: auto …for flex items in row-direction and column-direction, respectively. You can override these defaults by setting flex items to: min-width: … Read more