Tips for positioning an element at the bottom of a flexible container with variable size

How can I ensure that the Author element in this jsfiddle is aligned properly between the card elements? I am struggling to adjust the size of the details container to match the variable sizes of other elements in the same row.

The aim is to have the Author lines aligning horizontally across all rows.

.container {
  display: flex;
  flex-flow: row wrap;
  margin: 10px;
}

.card {
  width: 200px;
  margin: 10px;
}

.product_detail {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border: 1px solid pink;
}

.detail_item {
  border: 1px solid blue;
  flex: 1;
}

img {
  width: 100%;
}
<div class='container'>
  <div class="card">
    <section>
      <img src="https://c.booko.info/covers/34edd12eb5c21388/v/600.jpeg" itemprop="image" size="500x750">
    </section>
    <section class="product_detail">
      <div itemprop="name" class='detail_item'>
        <a href="https://booko.info">A Book Title</a>
      </div>
      <div class="detail_item">A Subtitle might be here</div>
      <div itemprop="author" class='detail_item'>Author</div>
    </section>
  </div>

  <div class="card">
    <section>
      <img src="https://c.booko.info/covers/34edd12eb5c21388/v/600.jpeg" itemprop="image" size="500x750">
    </section>
    <section class="product_detail">

      <div itemprop="name" class='detail_item'>
        <a href="https://booko.info">A Book Title which is much longer and takes up a few lines</a>
      </div>
      <div class="detail_item">A Subtitle might be here</div>
      <div itemprop="author" class='detail_item'>Author</div>
    </section>
  </div>
  <div class="card">
    <section>
      <img src="https://c.booko.info/covers/34edd12eb5c21388/v/600.jpeg" itemprop="image" size="500x750">
    </section>
    <section class="product_detail">
      <div itemprop="name" class='detail_item'>
        <a href="https://booko.info">A Book Title</a>
      </div>
      <div class="detail_item">A Subtitle might be here</div>
      <div itemprop="author" class='detail_item'>Author</div>
    </section>
  </div>
</div>

Answer №1

It seems like you are aiming to keep the Author div positioned at the bottom of each card.

If my understanding is correct, you were almost there. Here's what you needed:

  1. The .card div had to become a flex container

  2. The .product_detail section needed to expand to fill its available space

  3. The Author div should have been anchored to the bottom

These are the CSS changes that made it work:

.card {
  display: flex;
  flex-direction: column;
}

.product_detail {
  flex: 1;
}

.detail_item[itemprop="author"] {
  margin-top: auto;
}

Here is an updated Fiddle link for reference


Note: If you prefer not to evenly distribute the .detail_item divs vertically, simply remove the flex: 1; property from .detail_item, resulting in a layout similar to this.

I hope this information helps. Best of luck with your project!

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

A see-through section with a border that fades in transparency

Can anyone help me with creating a box with a unique design using CSS only? I want the box to have a rounded border that starts at 80% opacity at the top and gradually fades to 20% opacity at the bottom. Additionally, the border should start at 80% opaque ...

Pictures glide within containers

Hey, I'm having an issue with my images. They're not floating like they should be, even though they are centered in the div. I really want them to float and be centered. Here's the code snippet I've been working with. HTML <div cla ...

How to Align Navigation Bar Items to the Right in Bootstrap 4

I need some help with bootstrap. I've looked at various discussions on this topic and tried numerous solutions, but I still can't get it right. I want the logo to be on the left and the navigation links aligned to the right. Here's what I&ap ...

Adding custom fonts to DOMPDF: a step-by-step guide

First, I moved the dompdf library folder to /dompdf Next, I added a /fonts folder containing Roboto-Black.ttf Then, I created an index.php file <?php // Autoloader inclusion require_once 'dompdf/autoload.inc.php'; // Namespace reference ...

What is the best way to position this material-ui select list at the bottom of the input block for proper alignment?

My material-ui select build is working fine overall, but I'm looking to align the top line of the select list with the bottom line of the input block. Any ideas on how to achieve this? This is my code: const styles = theme => ({ formControl: { ...

`Animate your divs with slide in and slide out effects using

Currently, I am in the process of replicating a website and facing some challenges. This site is my inspiration for the project. I have managed to create a sliding effect using CSS, making the div slide in and out from the same direction. However, I want ...

Set a consistent pixel measurement for all images

I am working on a project where I have an image of a card that needs to be repeated 30 times. Each time the card is repeated, I want it to overlap with the previous card in a specific position, resembling a deck of cards. The issue I am facing is that whe ...

Tips for executing a function in the HC-Sticky plugin?

Currently, I am utilizing the HC-Sticky JavaScript plugin and endeavoring to utilize the documented reinit method. However, I am facing difficulty in understanding how to execute it. In this CodePen demo, a basic setup is displayed along with an attempt t ...

Issues with IE 11: SVG Map Not Triggering Mouseenter or Mouseleave Events

I've been grappling with this issue for the past couple of days and despite trying numerous solutions, nothing seems to be working. My SVG map of the US has jQuery mouseenter and mouseleave events that function properly in browsers other than IE 11 ( ...

Hover-activated dropdown menu

After reading numerous tutorials and spending hours trying to create a submenu on hover, I still can't seem to get it to work. My goal is to display "Zimmer", "Reservierung", and "Preise" in a vertical menu when hovering over "Hotel," and so on. Here ...

Reposition icons to the center within the icon-div container

I am trying to center align the elements in my icon-div as shown in the wireframe image. What steps should I take to achieve this layout? HTML: <div class="icons_div"> <div class="row bg-secondary"> <div class="col-sm-2"> ...

Error encountered during Bootstrap 4 SCSS compilation: Invalid US-ASCII character identified as "xE2"

Encountering difficulties when compiling certain bootstrap 4 modules (switching from beta3). Despite the fact that the issue can be resolved by adding @charset: 'UTF-8'; to the _hover.scss mixin partial (which is flagged as deprecated within the ...

Exploring jQuery Animation Effects: Enhancing Your Web Experience with Zoom In and Zoom Out

Is there a way to animate a logo using jQuery automatically upon page load? I want the image to zoom out, then zoom in and change to a different image. Can someone please assist me with this task? Below is the code snippet that I have: $(document).ready ...

Changing the text of a link when hovering - with a transition

Seeking a straightforward way to change text on a link upon :Hover. I desire a gentle transition (text emerges from below) and fallback to default if JavaScript is disabled. HTML <div class="bot-text"> <a href="">Visit this site</a> ...

The chaotic world of Android WebKit versions 2.x and 3.x

I have been working on an Android app and my goal is to make it compatible with Android versions 2.2 and above. Currently, due to issues with the WebView control, I am restricted to targeting Android 4.0 and higher. The app primarily uses HTML, CSS, Java ...

modify the color of a box within a grid upon clicking it

I am curious if it is possible to change the color of a box when it is clicked. I am working on coding a "calculator layout" and would like to start with this part 1 2 3 4 5 6 7 8 9 0 This is what I have been working on and struggling with. $(docume ...

Having Trouble with Your Instafeed Script

I've been working on a project that involves integrating an Instagram feed into a website. However, I'm facing difficulties getting it to function properly. Here's the code that I have implemented. <script type="text/javascript"> ...

Ways to customize background color for a particular date?

I have been using the fullcalendar npm package to display a calendar on my website. I am trying to figure out how to set a background color for a specific selected date. I tried looking into this issue on GitHub at this link. However, it seems that dayRe ...

Stylish Card Design

Below is the CSS code: *{margin:0; padding:0; box-sizing:border-box; } img{ display:block; max-width:100%; height:auto; } html{ scroll-behavior:smooth; } body{ min-height:100vh; font-family:fantasy; font-size:1.12 ...

Maintain the text layout when copying and pasting from the Angular Application

After noticing that copying and pasting text from an Angular Application to a text editor like Microsoft Word results in losing the original format, I decided to investigate further. An example I used was the angular material website: https://material.ang ...