Ask Your Question
1

How can I make a div with an automatic height using display:flex for product display?

asked 2023-05-09 15:22:24 +0000

pufferfish gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-05-09 15:40:02 +0000

lakamha gravatar image

To create a product display using flexbox with an automatic height, follow these steps:

  1. Create a parent container element for the product display with the desired width and margin properties.

  2. Set the display property of the parent container to flex.

  3. Set the flex-wrap property to wrap so that the products wrap to the next line as the container width decreases.

  4. Create child elements within the parent container for each product to be displayed.

  5. Set the width and margin properties of each child element to achieve the desired spacing and layout.

  6. To ensure that each child element has an automatic height, set the align-self property to stretch.

Here is an example CSS code:

.product-container { width: 100%; display: flex; flex-wrap: wrap; justify-content: space-between; margin: 0 auto; }

.product { width: 48%; margin-bottom: 30px; align-self: stretch; }

You can adjust the width percentages and margins to your liking depending on the number of products you want to display and the spacing between them.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-09 15:22:24 +0000

Seen: 8 times

Last updated: May 09 '23