Forming a row in flexbox with consistent layouts *across each line*

I want to create a flexbox layout where all the titles are aligned in a row. Here are the requirements:

  1. The images may vary in height
  2. The descriptions may vary in height
  3. The title could be displayed in 1 or 3 rows, depending on its length.

Check out this simple fiddle:

https://jsfiddle.net/youradds/r56j4uLe/6/

Here is the current output:

https://i.sstatic.net/aY12K.png

This is how I envision it:

https://i.sstatic.net/3xGAu.png

Below is my SCSS code:

#item-wrapper {

    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;

    .item-block {

    background: yellow;

        flex-grow: 0;
        width: 350px;
        margin: 2rem 1rem;

        display: flex;
        flex-direction: column;
        justify-content: space-between;
        align-content: center;
        align-items: center;

        .what-logo {

            img {
                max-height: 100%;
            }
        }

        .text-info {
            flex-grow: 1;

            .desc {
                padding: 1rem;
            }

            h2 {
                flex-grow: 0;
            }

        }


        .action-button {
            margin: 0 auto;
        }



    }
}

.pure-img {
  max-width: 100%;
  height: auto;
  display: block;
}

Test HTML snippet:

<div id="item-wrapper">
    <div class="item-block">
        <div class="what-logo">
            <img src="https://bodywisegym.co.uk/2018/images/events/3/3-1562951826-3.png" class="pure-img">
        </div>
        <div class="text-info">
            <h2>Zydrunas Savickas Seminar</h2>
            <div class="desc">Bodywise Gym and Studios are proud to announce we are bringing the greatest strongman Zydrunas Savickas (Big Z) to Horsham for a seminar.</div>
        </div>
        <a href="https://yogida.co.uk/collections/events/products/zydrunas-savickas-big-z-seminar" class="action-button">Find out more &raquo;</a>
    </div>

    <div class="item-block">
        <div class="what-logo">
            <img src="https://bodywisegym.co.uk/2018/images/events/7/7-1562936970-7.jpg" class="pure-img">
        </div>
        <div class="text-info">
            <h2>Class for mums</h2>
            <div class="desc">Join Quick HIIT</div>
        </div>
        <a href="" class="action-button">Find out more &raquo;</a>
    </div>

    <div class="item-block">
        <div class="what-logo">
            <img src="https://bodywisegym.co.uk/2018/images/events/6/6-1562936464-6.png" class="pure-img">
        </div>
        <div class="text-info">
            <h2>Gratitude Day</h2>
            <div class="desc">To spread the positivity you can bring a training partner along to workout with you or to attend one of our classes.</div>
        </div>
        <a href="" class="action-button">Find out more &raquo;</a>
    </div>

    <div class="item-block">
        <div class="what-logo">
            <img src="https://bodywisegym.co.uk/2018/images/events/4/4-1562951950-4.jpg" class="pure-img">
        </div>
        <div class="text-info">
            <h2>The experience of non-duality</h2>
            <div class="desc">Yoga & meditation workshop with Indian Spiritual Master Acharya Shree Shankar </div>
        </div>
        <a href="https://yogida.co.uk/collections/workshops" class="action-button">Find out more &raquo;</a>
    </div>
</div>  

Note: This design is responsive, so setting a fixed height on image divs may not work well across different screen sizes:

https://i.sstatic.net/tz2Wg.png

On smaller screens, scaling down to 1 element per row may lead to excessive padding between the image and title like shown here:

https://i.sstatic.net/E8o1y.png

Answer №1

Consider finding a visual compromise that works for all elements.

Flex children within different flex parents do not align by default.

To address this issue, try centering tex-info and what-logo, while also adding an average min-height to .desc.

View the demo below in full page mode to test the behavior and visual appearance.

#item-wrapper {
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
}

#item-wrapper .item-block {
  background: yellow;
  max-width: 350px;
  margin: 2rem 1rem;
  padding:2px;/* see me */
  display: flex;
  flex-direction: column;
  align-items: center;
}

#item-wrapper .item-block .what-logo img {
  max-height: 100%;
}

#item-wrapper .item-block .text-info,
#item-wrapper .item-block .what-logo {/* update */
  margin-top: auto;
}

#item-wrapper .item-block .text-info .desc {
  padding: 1rem;
  min-height: 4em;/* 3 lines , average */
}

#item-wrapper .item-block .text-info h2 {text-align:center}

#item-wrapper .item-block .action-button {
  margin: 0 auto;
}

.pure-img {
  max-width: 100%;
  height: auto;
  display: block;
}
<div id="item-wrapper">
  <div class="item-block">
    <div class="what-logo">
      <img src="https://bodywisegym.co.uk/2018/images/events/3/3-1562951826-3.png" class="pure-img">
    </div>
    <div class="text-info">
      <h2>Zydrunas Savickas Seminar</h2>
      <div class="desc">Bodywise Gym and Studios are proud to announce we are bringing the greatest strongman Zydrunas Savickas (Big Z) to Horsham for a seminar.</div>
    </div>
    <a href="https://yogida.co.uk/collections/events/products/zydrunas-savickas-big-z-seminar" class="action-button">Find out more &raquo;</a>
  </div>

  <div class="item-block">
    <div class="what-logo">
      <img src="https://bodywisegym.co.uk/2018/images/events/7/7-1562936970-7.jpg" class="pure-img">
    </div>
    <div class="text-info">
      <h2>Class for mums</h2>
      <div class="desc">Join Quick HIIT</div>
    </div>
    <a href="" class="action-button">Find out more &raquo;</a>
  </div>

  <div class="item-block">
    <div class="what-logo">
      <img src="https://bodywisegym.co.uk/2018/images/events/6/6-1562936464-6.png" class="pure-img">
    </div>
    <div class="text-info">
      <h2>Gratitude Day</h2>
      <div class="desc">To spread the positivity you can bring a training partner along to workout with you or to attend one of our classes.</div>
    </div>
    <a href="" class="action-button">Find out more &raquo;</a>
  </div>

  <div class="item-block">
    <div class="what-logo">
      <img src="https://bodywisegym.co.uk/2018/images/events/4/4-1562951950-4.jpg" class="pure-img">
    </div>
    <div class="text-info">
      <h2>The experience of non-duality</h2>
      <div class="desc">Yoga & meditation workshop with Indian Spiritual Master Acharya Shree Shankar </div>
    </div>
    <a href="https://yogida.co.uk/collections/workshops" class="action-button">Find out more &raquo;</a>
  </div>
</div>

Check out the forked fiddle here

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

Ways to center text without using the span tag

Is there a way to align text in the center without using the span tag? I want the text to be centered with other content on the sides not interfering. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" ...

Modify the h1 heading text using JavaScript without affecting any other html elements

My aim is to update the content of the h1 tag without affecting any other inner HTML elements. Below is the code I have used: document.getElementById("wpbody-content").getElementsByClassName("wrap")[0].getElementsByTagName('h1')[0].innerHTML = & ...

Issues with positioning images using media queries

Can anyone help me center an img when the viewport width is 320px? I've attempted different approaches but so far, nothing has been successful. .logo { width: 55px; height: 55px; margin: 10px 0 10px 30px; float: left; } @media only screen a ...

Encountered a deployment issue when trying to deploy an HTML application on Heroku due

After uploading an html application on GitHub, I encountered an error while attempting to deploy it on Heroku: No default language could be detected for this app. HINT: This happens when Heroku is unable to automatically determine the buildpack to use f ...

Trouble pausing CSS slide using -webkit-animation-play-state:paused; finding it ineffective

Below is the code snippet in question: .picTransition .item { position: absolute; left: 0; right: 0; opacity: 0; -webkit-animation: picTransition 56s linear infinite; -moz-animation: picTransition 56s linear infinite; -ms-animation: ...

Developing an animated feature that displays a dynamic count up to the current size of the browser window

I have a script that's able to determine the height and width of my browser window. However, I am facing a challenge in creating a way for these dimensions to count up from zero to their current values upon loading. The desired functionality would be ...

Replacing menu styling with JavaScript using C#

I'm currently working on a C# project to develop a smartphone-friendly website for motorists to easily pay their parking fees. However, I'm facing some challenges with the menu design. My goal is to have a white menu with black text, where the cu ...

Displaying the template of a subclass component in Angular 4

Is there a way to display a list of items (components) based on their types in Angular? I currently have an array of components that all inherit from a base class. The array type is defined as the base class, but I would like each item in the array to be ...

Using Jquery to Retrieve the Content of Head and Body Tags from a String

Here is a string that I currently have: <head> This is the Head </head> <body> <div> <div> <p> Body Content <br /></p> <p>&nbsp; Hello World <br />< ...

Transferring the selected radio button from one HTML page to another without using PHP

I'm looking to transfer radio button data from the first HTML to the second using Pure JavaScript Feel free to use jQuery if needed. jQuery was used 1st HTML <body> <label for="1"> <input type="radio" name="num" id="1" checked="che ...

Can anyone tell me the best way to access the name attribute of an HTML element in TypeScript?

Currently, my code is utilizing the name attribute to verify whether the user has entered information in a specific field and validating the input. However, I am facing an issue where the submit button remains active even if there are empty fields presen ...

Can someone please explain the purpose of document.reservation.submit();?

As I delve into the code of a previous developer, my focus is on creating a reservation form. After a thorough review, it seems that the only reference to "reservation" is in the name and ID of the form. The form's style includes: display:none ... ...

Is there a method to track the progress of webpage loading?

I am working on a website built with static HTML pages. My goal is to implement a full-screen loading status complete with a progress bar that indicates the page's load progress, including all images and external assets. Once the page has fully loaded ...

The icons from MaterializeCSS are not displaying correctly on the navbar within an Angular 7 project

Having an issue implementing MaterializeCSS Icons on the navbar. The arrow-drop_down icon is not displaying correctly, showing only text instead. Oddly enough, the icons render properly on other pages except for the app.component.html file. I attempted to ...

What is the method for emphasizing links in the navigation bar with Bootstrap 3?

I am currently working on applying custom CSS styles to the Bootstrap navbar in order to have the link text underlined when hovered over, with a fade-in effect as well. To see what I have accomplished so far, you can view it here: https://jsfiddle.net/xfd ...

Populate HTML textboxes with data from a MySQL database when a button is clicked

I have a simple form for updating existing data entries. For this form, I use PHP to populate the dropdown menu with Service IDs. Once the user clicks the Load button, the goal is to show additional information related to that ID in the textboxes below. H ...

Rotating Images in Query and Chrome

My script for rotating images is functioning well in various browsers, however, it seems to be experiencing issues specifically with Google Chrome. In order to address this problem, I attempted a CSS3 workaround. Unfortunately, I have encountered difficul ...

Element was removed upon clicking only once

Can anyone help me figure out why the behavior of .remove() with $postNav.remove(); is different here? When you click on "I'm a tag" for the first time, both the <li> and <ol> are deleted as expected. However, on the second click, only the ...

I attempted to apply vertical-align and color properties to the static_nav div, but they didn't have any effect. Could this be due to its placement within the header? What steps should I take to resolve this issue?

<!DOCTYPE HTML> <html lang ="en"> <meta charset = "utf-8" /> <head> <title>Sample Page</title> <link rel="stylesheet" type="text/css" href="Web_Design_01_Stylesheet.css" /> </head> <body> &l ...

bespoke filter designed to conceal any negative figures

I am trying to implement a feature where a text box will display nothing if the ng-model contains a negative value. I want the ng-model to remain unchanged while ensuring that negative values are not displayed. I am looking for a custom filter to achieve t ...