Blog Single

CREATING INVERSE TRIANGLE ROWS WITH CSS GRID AND FLEXBOX

Sometimes a client has an odd number of items in a columned layout. Usually it’s in the last row and there’s either a missing spot or it’s centered under the other items. But recently, I’ve had a few clients who wanted to do an inverse layout – where the row with the less items is in the first row centered, above a row with the full number of items. It’s actually surprisingly difficult to do this, even with modern tools like Flexbox and Grid. Both ways have their pros and cons, and neither is super simple – especially if the client decides they want to add or remove items in the future. Let’s take a look at both approaches:

FLEXBOX

The only way I could think of accomplishing this in Flexbox was to add a containing element to each row. This has the obvious drawback of requiring an additional HTML element, which isn’t the cleanest, as well as requiring specific widths.

#2. GRID

Temporibus ad error

Quisquam esse aliquam fuga distinctio, quidem delectus veritatis reiciendis. Nihil explicabo quod, est eos ipsum. Unde aut non tenetur tempore, nisi culpa voluptate maiores officiis quis vel ab consectetur suscipit veritatis nulla quos quia aspernatur perferendis, libero sint. Error, velit, porro. Deserunt minus, quibusdam iste enim veniam, modi rem maiores.

Odit voluptatibus, eveniet vel nihil cum ullam dolores laborum, quo velit commodi rerum eum quidem pariatur! Quia fuga iste tenetur, ipsa vel nisi in dolorum consequatur, veritatis porro explicabo soluta commodi libero voluptatem similique id quidem? Blanditiis voluptates aperiam non magni. Reprehenderit nobis odit inventore, quia laboriosam harum excepturi ea.

Adipisci vero culpa, eius nobis soluta. Dolore, maxime ullam ipsam quidem, dolor distinctio similique asperiores voluptas enim, exercitationem ratione aut adipisci modi quod quibusdam iusto, voluptates beatae iure nemo itaque laborum. Consequuntur et pariatur totam fuga eligendi vero dolorum provident. Voluptatibus, veritatis. Beatae numquam nam ab voluptatibus culpa, tenetur recusandae!

Voluptas dolores dignissimos dolorum temporibus, autem aliquam ducimus at officia adipisci quasi nemo a perspiciatis provident magni laboriosam repudiandae iure iusto commodi debitis est blanditiis alias laborum sint dolore. Dolores, iure, reprehenderit. Error provident, pariatur cupiditate soluta doloremque aut ratione. Harum voluptates mollitia illo minus praesentium, rerum ipsa debitis, inventore?

Image placeholder

Irena

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ducimus itaque, autem necessitatibus voluptate quod mollitia delectus aut, sunt placeat nam vero culpa sapiente consectetur similique, inventore eos fugit cupiditate numquam!

6 Comments

  • Image placeholder

    Lenny Parker

    October 03, 2018 at 2:21pm

    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur quidem laborum necessitatibus, ipsam impedit vitae autem, eum officia, fugiat saepe enim sapiente iste iure! Quam voluptas earum impedit necessitatibus, nihil?

    Reply

  • Image placeholder

    Lenny Parker

    October 03, 2018 at 2:21pm

    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur quidem laborum necessitatibus, ipsam impedit vitae autem, eum officia, fugiat saepe enim sapiente iste iure! Quam voluptas earum impedit necessitatibus, nihil?

    Reply

    • Image placeholder

      Lenny Parker

      October 03, 2018 at 2:21pm

      Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur quidem laborum necessitatibus, ipsam impedit vitae autem, eum officia, fugiat saepe enim sapiente iste iure! Quam voluptas earum impedit necessitatibus, nihil?

      Reply

      • Image placeholder

        Aileen Doe

        October 03, 2018 at 2:21pm

        Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur quidem laborum necessitatibus, ipsam impedit vitae autem, eum officia, fugiat saepe enim sapiente iste iure! Quam voluptas earum impedit necessitatibus, nihil?

        Reply

        • Image placeholder

          Aileen Doe

          October 03, 2018 at 2:21pm

          Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur quidem laborum necessitatibus, ipsam impedit vitae autem, eum officia, fugiat saepe enim sapiente iste iure! Quam voluptas earum impedit necessitatibus, nihil?

          Reply

  • Image placeholder

    Aileen Doe

    October 03, 2018 at 2:21pm

    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Pariatur quidem laborum necessitatibus, ipsam impedit vitae autem, eum officia, fugiat saepe enim sapiente iste iure! Quam voluptas earum impedit necessitatibus, nihil?

    Reply

Leave a comment