Tips for aligning column components in a vertical position

My task is to align vertically the elements within multiple columns that include a headline, a description, and a button. By default, each element expands based on its content size

https://i.stack.imgur.com/RJJP4.png

However, I need all elements to be aligned so that all headlines, descriptions, and buttons start at the same height.

https://i.stack.imgur.com/mZL2Z.png

I suspect that flexbox may not be the solution here, but perhaps using CSS grid or applying display: table and restructuring everything in such a format could work. Unfortunately, I have been unable to make it function as desired.

The current code structure appears like this:

<ul>
  <li class="columns large-4 small-12 medium-4 s-pb-30">
    <h3>Some headline</h3>
    <div>
      <p>
        Lorem ipsum dolor sit amet consectetur adipisicing
        elit. Nostrum facilis praesentium quaerat,
        laboriosam ratione eos. Lorem ipsum dolor sit amet
        consectetur adipisicing elit. Nostrum facilis
        praesentium quaerat, laboriosam ratione eos. Lorem
        ipsum dolor sit amet consectetur adipisicing elit.
        Nostrum facilis praesentium quaerat, laboriosam
        ratione eos.
      </p>
      <a class="button btn-styled center-block--btn" href="/">Foo</a>
    </div>
  </li>
  <li class="columns large-4 small-12 medium-4 s-pb-30">
    <h3>Another headline</h3>
    <div>
      <p style="height: 360px;">
        Lorem ipsum dolor sit amet consectetur adipisicing
        elit. Nostrum facilis praesentium quaerat,
        laboriosam ratione eos. Lorem ipsum dolor sit amet
        consectetur adipisicing elit. Nostrum facilis
        praesentium quaerat, laboriosam ratione eos.
      </p>
      <a class="button btn-styled center-block--btn" href="/">Bar Bar Bar Bar Bar Bar Bar Bar Bar Bar Bar Bar Bar Bar
        Bar Bar </a>
    </div>
  </li>
  <li class="columns large-4 small-12 medium-4 s-pb-0">
    <h3 class="title">Surprisingly here's a third headline that should be aligned with the other two</h3>
    <div>
      <p style="height: 360px;">
        Lorem ipsum dolor sit amet consectetur adipisicing
        elit. Nostrum facilis praesentium quaerat,
        laboriosam ratione eos.
      </p>
      <a class="button btn-styled center-block--btn" href="/">Baz</a>
    </div>
  </li>
</ul>

Answer №1

To create a CSS grid that fills up column-first instead of row-first, define an implicit CSS grid and use grid-auto-flow: column.

grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: auto 1fr auto;
grid-auto-flow: column;

Keep in mind that 1fr is greedy while auto is not, allowing the middle row (where the <p> tags are) to expand as needed.

Due to limited support for CSS subgrid in browsers currently, make sure all elements in the grid are siblings by "unpacking" individual <li> content.

For the button styling, utilize fit-content for both width and height, and center it horizontally with margin: 0 auto.

Check out the example below:

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: auto 1fr auto;
  grid-auto-flow: column;
  text-align: center;
}

.grid a {
  display: block;
  background-color: steelblue;
  color: #fff;
  border-radius: 100vh;
  width: fit-content;
  height: fit-content;
  margin: 0 auto;
  padding: .5em 1em;
  text-decoration: none;
}
<div class="grid">
  <h3>Some headline</h3>
  <p>
    Lorem ipsum dolor sit amet consectetur adipisicing elit. Nostrum facilis praesentium quaerat, laboriosam ratione eos. Lorem ipsum dolor sit amet consectetur adipisicing elit. Nostrum facilis praesentium quaerat, laboriosam ratione eos. Lorem ipsum dolor sit amet consectetur adipisicing elit. Nostrum facilis praesentium quaerat, laboriosam ratione eos.
  </p>
  <a href="/">Foo</a>

  <h3>Another headline</h3>
  <p>
    Lorem ipsum dolor sit amet consectetur adipisicing elit. Nostrum facilis praesentium quaerat, laboriosam ratione eos. Lorem ipsum dolor sit amet consectetur adipisicing elit. Nostrum facilis praesentium quaerat, laboriosam ratione eos.
  </p>
  <a href="/">Bar Bar Bar Bar Bar Bar Bar Bar Bar Bar Bar Bar Bar Bar Bar Bar </a>

  <h3 class="title">Surprisingly here's a third headline that should be aligned with the other two</h3>
  <p>
    Lorem ipsum dolor sit amet consectetur adipisicing elit. Nostrum facilis praesentium quaerat, laboriosam ratione eos.
  </p>
  <a href="/">Baz</a>
</div>

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

I encounter issues when trying to run "yarn start" following the integration of tailwindcss into my React project

I'm encountering an issue while integrating tailwindcss with postcss into my React Application (built using create-react-app). To address this, I modified the scripts section in my package.json. Here is how my updated package.json appears: { "name ...

Is there a way to send me the result of the radio input (Yes/No) via email?

Is it feasible to send the results of a radio input (Yes/No) back to my email directly using HTML, CSS, and Javascript? ...

Ensure that data is not cached after the page is refreshed at regular intervals of x seconds

In the process of developing a news app, I have implemented a feature where a div with the class .new_feed is refreshed every 10 seconds to fetch new updates. However, I encountered an issue where if a new feed appears in the .new_feed div and is not cli ...

When I attempt to view my calendar in a modal popup, the opening action causes it

Recently, I encountered an issue with the bootstrap datepicker in a modal pop-up. The problem arises when it gets cut off unexpectedly. I am seeking suggestions or solutions to resolve this inconvenience. <input id="doohMediaStartDate" name="startDate" ...

Image not appearing when sharing on Facebook

I've been trying to create a Facebook share button using the Javascript SDK, and here is the code I have been utilizing: $(function() { $('.facebook-share').click(function(e) { e.preventDefault(); FB.ui({ method: 'feed& ...

How to position a Navbar on top of a grid background structure

I am currently working on developing a responsive website, and I have encountered a challenge that I need help with. I am looking to create a header using a grid system, where I have divided the header into two parts: col-md-4 : For an Image col-md-7 : ...

Is the phrase "This site was built with Wix" visible on the website?

Recently, I've begun using Wix to build a website. I'm curious - does the message 'This website is created using Wix' appear at the top and bottom of the page when it's published? 'This website is created using Wix' I ...

Invalid Value Provided for CSS Clip Path

I'm currently attempting to design a sophisticated clip-path using a logo in CSS, but I keep receiving an error stating "Invalid Property Value." The X and Y coordinates have been computed based on dimensions of 508px x 190px This is the logo that is ...

Move a 'square' to a different page and display it in a grid format after clicking a button

I am currently developing a project that allows students or schools to add projects and search for collaborators. On a specific page, users can input project details with a preview square next to the fields for visualization. Once the user uploads the ...

Changes to attributes of an HTML tag cannot be made by jQuery code during an AJAX call

Could someone help me figure out why this jQuery code is not functioning properly? I have already tested it outside the $(document).ready block with no success. Note: The unusual "{{ }}" and "{% %}" syntax is typically used in Django. jQuery $(document) ...

Activate HTML event upon reaching a specific point while scrolling, and then reactivate by scrolling back

I'm encountering an issue where the fade effect triggers when I scroll past a certain point, but then fails to fade back in once I scroll back. Is my approach correct or am I missing something? Currently, it fades out abruptly at a specific point and ...

What is the best way to utilize Rselenium's findElement() function in order to target an xpath based on its text content

Despite researching similar questions on stack overflow, I have not been able to make my code work. Here is the initial code I am working with: library(RSelenium) library(rvest) remote_driver <- RSelenium::remoteDriver( remoteServerAddr = "local ...

Unable to get compatibility mode IE to work as intended

I am facing an issue where I need to showcase a webpage in compatibility mode. Despite using the code below: <meta http-equiv="X-UA-Compatible" content="IE=11"> It seems like this code only functions if compatibility mode is already enabled. In tha ...

Scrollable Tailwind components

I am working on creating a page layout similar to this design: here is what I want to achieve The goal is to have a simple homepage with a navbar and split screen. The challenge is to prevent the entire page from scrolling normally and enable independent ...

"How can I adjust the height of a Bootstrap column to match the height of its neighboring column

In my Bootstrap 4 layout, I have set up two columns... The left column contains three cards in columns The right column has a list group The content in the list group is longer than that of the cards on the left side. Is there a way to make the height ...

how to change the class of a div when clicking on a <p> element

Check out this code snippet: <p class="faq" onclick="toggleVisibility('answer1');"> How can I restrict email sending on my website? </p> <div id="answer1" class="hide"><sometext></div> these are my CSS styles! ...

Setting the Disabled and Checked attributes on HTML Elements based on certain conditions

Within an asp GridView template field, there is a button and a checkbox. The goal is to set the disabled property of the button and the checked property of the checkbox based on the Data Field Expiration conditionally. If the Expiration equals Permanent, t ...

Issues with Image Placement in Internet Explorer

My cat image on my website appears significantly lower than all the other images when viewed on Internet Explorer (v11). While it looks perfect in Chrome, I cannot figure out why this discrepancy exists. For the development of this website, I utilized pred ...

How to load a URL into a div using jQuery and then update the div with new content?

I have a codeigniter view that I want to load into a div as an iframe using the following code: <script type='text/javascript'> $(document).ready(function (){ $('#divId').load('http://www.domain.oo/page.php?test=1); }); ...

Understanding the fundamentals of positioning elements in CSS as they float on a webpage

Understanding the behavior of float in CSS can be confusing. When floating an element to the left or to the right, it affects how other elements wrap around it. But why do some elements wrap while others don't? For example, when you have a floated im ...