Achieve bottom alignment for an element inside a flexbox, all without the need for position:absolute

Check out the jsfiddle provided: https://jsfiddle.net/q3ob7h1o/1/ Alternatively, you can read the code here:

Code

* {
  margin: 0;
  padding: 0;
}
ul {
  display: -webkit-flex;
  display: flex;
  -webkit-flex-flow: row wrap;
  flex-flow: row wrap;
  flex-direction: row;
  flex-wrap: wrap;
  -webkit-align-content: flex-end;
  align-content: flex-end;
}
.tile {
  width: 33%;
  display: inline-block;
  box-sizing: border-box;
  position: relative;
}
.content {
  background: beige;
}
.footer {
  background: teal;
}
<ul>
  <li class="tile">
    <div class="content">
      <div class="photo"></div>
      <h3>This is some long long long long long long long long long long long long long long long long content</h3>
    </div>
    <div class="footer">
      <input type="submit" />
    </div>
  </li>
  <li class="tile">
    <div class="content">
      <div class="photo"></div>
      <h3>This is some content</h3>
    </div>
    <div class="footer">
      <input type="submit" />
    </div>
  </li>
  <li class="tile">
    <div class="content">
      <div class="photo"></div>
      <h3>This is some content</h3>
    </div>
    <div class="footer">
      <input type="submit" />
    </div>
  </li>
</ul>

Objective

The goal is to align the .footer div to the bottom of each .tile element, ensuring that the footers are in line regardless of the content length within each tile.

Although using position: absolute on the footer could work, it's preferable to avoid it since the footer height may vary.

Attempts have been made to turn .tile into a flexbox and set its direction to column, but this approach didn't yield the desired results. Similarly, transforming each tile into a table-cell also proved ineffective.

The challenge lies in targeting an element within a child of an existing flexbox. Any flexbox properties applied target .tile rather than .footer.

Any assistance would be greatly appreciated :)

Answer №1

Check out the solution below:

* {
  margin: 0;
  padding: 0;
}
ul {
  display: -webkit-flex;
  display: flex;
  -webkit-flex-flow: row wrap;
  flex-flow: row wrap;
  flex-direction: row;
  flex-wrap: wrap;
  -webkit-align-content: flex-end;
  align-content: flex-end;
}
.tile {
  width: 33%;
  display: flex;
  box-sizing: border-box;
  justify-content: space-between;
  flex-direction:column;
}
.content {
  background: beige;
}
.footer {
  background: teal;

}
<ul>
  <li class="tile">
    <div class="content">
      <div class="photo"></div>
      <h3>This is some long long long long long long long long long long long long long long long long content</h3>
    </div>
    <div class="footer">
      <input type="submit" />
    </div>
  </li>
  <li class="tile">
    <div class="content">
      <div class="photo"></div>
      <h3>This is some content</h3>
    </div>
    <div class="footer">
      <input type="submit" />
    </div>
  </li>
  <li class="tile">
    <div class="content">
      <div class="photo"></div>
      <h3>This is some content</h3>
    </div>
    <div class="footer">
      <input type="submit" />
    </div>
  </li>
</ul>

To view the updated fiddle, click on this link: https://jsfiddle.net/abc123xyz/

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 create a uniquely scrollable div in React Bootstrap

Currently, I'm working on implementing React Bootstrap for my website. I am having trouble figuring out how to make only one specific div scrollable while keeping the others fixed. Below is a snippet of my code located in App.js import * as React from ...

Troubleshooting compatibility issues between JS and ng-view in AngularJS

In my AngularJS SPA project, I am using ngRoute along with Bootstrap's Carousel template. However, I have run into an issue where certain functionalities ceased to work once I started using ng-view instead of placing all the main content in the index. ...

How can the bootstrap mega menu be modified to use an onclick function and incorporate drop-down items for mobile users?

Is it possible to change the drop-down menu behavior for small devices to make it work on click instead of hover? The issue I'm facing is that the sub-menus are appearing outside the root navigation on mobile devices. How can I modify the code to ensu ...

Capture and reroute the loading of stylesheets, images, and fonts coming from Gecko

Seeking guidance for a C# application utilizing geckofx. I am looking to intercept and redirect the loading of images, fonts, and style sheets. My goal is to potentially load these resources from a database. I've experimented with SetParentURIContentL ...

Creating anchor links with #id that function correctly in an Angular project can sometimes be challenging

My backend markdown compiler generates the HTML content, and I need Angular to retrieve data from the server, dynamically render the content, and display it. An example of the mock markdown content is: <h1 id="test1">Test 1<a href="#test1" title ...

Using Bootstrap can cause CSS to become cluttered and disorganized

I created a basic burger button using HTML and CSS, everything was working perfectly until I decided to incorporate Bootstrap into my project for alignment purposes, which ended up causing conflicts with my existing CSS. Instead of adding Bootstrap, http ...

Is there a way to shift the button over to the left?

I am currently utilizing the modalExample provided in the Bootstrap documentation. <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">Open modal</button> <di ...

Save data to local storage using the 'onclick' event in jQuery

I'm facing an issue with local storage. My portfolio includes my work, contacts, etc., and I lack buttons that can toggle between Swedish and English languages when clicked. How can I use local storage to remember the language choice even after refres ...

Why is the bootstrap modal not showing up when editing the data?

I am currently working on a Blazor application with .NET Core 7. I am facing an issue where the Bootstrap modal does not display as active when clicking the edit button. When trying to edit data using the Bootstrap modal, the modal does not display as act ...

What is the best method for inserting every item from a textarea into my database?

I have encountered an issue with the code I am currently using. I have a modified version of this code implemented on another page, where a textbox is used instead of a textarea. Interestingly, the textbox version works perfectly fine. However, on my cur ...

An issue occurred in the evaluation of tidy when attempting to access the object 'titles' in the mask

Whenever I attempt to run this code, an error pops up. My goal is to extract data from multiple pages. However, when executing the script below, I encounter the following error message: Error in eval_tidy (xs [[j]], mask): object 'titles' not f ...

Launching a HTML hyperlink inside a div with the power of jQuery

I am currently exploring the functionality of dragging and dropping an HTML link into a div element. My objective is to have the link open within that specific div element. The layout consists of two divisions named "left-panel" and "canvas". The concept ...

Displaying error message dynamically using ajax

I am looking to customize the way error messages are displayed on my form. Instead of having one generic div above the whole form, I want the error messages to appear next to each input field. <div id="response"><!--This section will show error ...

What is the most dependable method for referencing a CSS class through programming?

Within my Sharepoint project, I am dynamically generating controls in the overridden CreateChildControls() method. I am uncertain which approach is more preferable when it comes to referencing the .css file: protected override void CreateChildControls() { ...

Stylish CSS Card with set height and adaptive image

Looking for a way to set a fixed height for a file input with preview? Check out this Codepen example: Codepen In the HTML (vue component), there is a card element with an image that maintains its aspect ratio. However, you may want to fix the height of ...

What dimensions are optimal for images on a Responsive web design?

In the process of making our website responsive, I have a question regarding image sizes. If I want images to fill the entire screen, excluding the navigation header, what specific dimensions should these images be in order to display correctly on all type ...

Update the scope parameter in an alternate perspective

I've been struggling with a particular issue for quite some time now and I seem to be stuck. Here's what I'm trying to achieve: I want to change the value of my scope in one view by clicking on a button in another view. For instance, if I&ap ...

Text display appears uneven

After downloading the 'exo' font from Google Fonts, I was pleased with how it appeared on my htc smartphone. However, on my laptop screen, it looked as if a swarm of caterpillars had nibbled away at it. I attempted various techniques like anti-a ...

ways to add spacing between bootstrap columns

I am currently using Bootstrap 5 and I'm trying to create a row with 6 columns. I have added gutter in the row but for some reason, the spacing between the columns is not being applied. Can anyone help me figure out what I'm doing wrong here? Bel ...

Utilizing JQuery within dynamically loaded files through JQuery tab functionality

My initiation into the world of JQuery tabs has begun. I have a basic setup where clicking on a tab loads 3 different PHP files. <div id="info"> <ul id="info-nav"> <li><a href="tab1.php">Tab 1</a></li> ...