What causes the breakdown of flexbox when set to column and wrap?

Here is the code I am working with:

<div id="parent">
   <div class="produit_sup">
      <p>Aubergine</p>
      <p>Betterave</p>
      <p>Courgette</p>
      <p>Oignon</p>
      <p>Poireau</p>
      <p>Pomme de terre</p>
      <p>Tomate</p>
   </div>
</div>

<style>
#parent{
   display: flex;
}
.produit_sup{
   max-height: 100px;
   background: #c3c3ff;
   display: flex;
   flex-direction: column;
   flex-wrap: wrap;
}
.produit_sup>p{
   width: 100px;
   text-align: left;
   margin: 0 20px 0 0;
}
</style>

I am wondering why the layout looks like this:
https://i.sstatic.net/3yPFO.png

Instead of looking like this:
https://i.sstatic.net/7jVXo.png

I would like to maintain the display:flex; property of the parent element, and the number of <p> items may vary over time.

Answer №1

Consider adjusting the CSS for .produit_sup by adding properties like flex-basis or width, such as width:50%.

<div id="parent">
   <div class="produit_sup">
      <p>Eggplant</p>
      <p>Beetroot</p>
      <p>Zucchini</p>
      <p>Onion</p>
      <p>Leek</p>
      <p>Potato</p>
      <p>Tomato</p>
   </div>
</div>

<style>
#parent{
   display: flex;
}
.produit_sup{
   width: 50%;
   max-height: 100px;
   background: #c3c3ff;
   display: flex;
   flex-direction: column;
   flex-wrap: wrap;
}
.produit_sup>p{
   width: 100px;
   margin: 0 20px 0 0;
}
</style>

Answer №2

Here are a few options you can try:

  • Remove the flex property from your CSS for #parent
  • Change the direction of #parent to column
  • Adjust the width of #parent to a different value like 100% or 200px
<div id="parent">
   <div class="product_list">
      <p>Eggplant</p>
      <p>Beetroot</p>
      <p>Zucchini</p>
      <p>Onion</p>
      <p>Leek</p>
      <p>Potato</p>
      <p>Tomato</p>
   </div>
</div>

<style>
#parent{
   display: flex;
   flex-direction: column;
   width: 200px;
}
.product_list{
   max-height: 100px;
   background: #c3c3ff;
   display: flex;
   flex-direction: column;
   flex-wrap: wrap;
}
.product_list>p{
   width: 100px;
   text-align: left;
   margin: 0 20px 0 0;
}
</style>

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

Issues with retrieving $_POST values from a select form in PHP

When the button is clicked, I am sending a AJAX request to my PHP page using POST method with the selected data from a SELECT element. However, I am facing an issue where my PHP IF statements are not evaluating as true. It always defaults to the ELSE condi ...

The dropdown item in Tailwindcss is unexpectedly flying off the edge of the screen rather than appearing directly under the dropdown button

Currently, I am developing an application using Rails, Vue, and TailwindCss 1.0+ I am facing an issue while creating a dropdown menu for my products. When I click on the dropdown button, the items in the dropdown fly off to the edge of the screen instead ...

Issue with exchanging columns in Bootstrap version 5.0

Seeking assistance! I am a beginner with bootstrap and struggling to figure out an issue I'm experiencing. In the attached image(s), my goal is to have the coin image positioned above its corresponding text on the left side when the screen size is red ...

developing a PHP script that dynamically generates active classes

I am working on building a dynamic menu that is based on the categories stored in the database. I need the selected menu option to have the css class 'active', indicating which page the user is currently on. The pages themselves are also generate ...

Is there a way to create a Swipe slideshow without relying on plugins or external tools?

How can I create a responsive swipe image slideshow using CSS and JQuery that changes the image when swiping from right to left? I want it to work seamlessly on both computer and mobile screens. ...

Tips for positioning the search bar on the opposite side of the navbar in Bootstrap 5

In my navbar, I have items aligned on the left and a search bar aligned on the right. However, when I try to move the items to the right using the ms-auto class, only the items move and the search bar stays in place. How can I adjust the alignment so that ...

Using PHP to extract data from multiple HTML arrays

I am facing a challenge with using jQuery to dynamically add more input tags in order to collect multiple data and treat them as an array. However, when I process this with PHP, only one data is being sent. Can someone please assist me with this issue? &l ...

A guide on restricting overflow in React Spring Parallax 'pages'

Currently, I have integrated React Spring Parallax () into my project found at this link: https://codesandbox.io/s/parallax-sticky-scroll-2zd58?file=/src/App.js Upon clicking the button to navigate to the next section, it is noticeable that the image over ...

What is the best way to change the background color for my photo gallery?

I'm currently working on a project to create a unique photo gallery where each image has a different colored background. I have six images in total, but right now all of them have a pink background. I've attempted adding another .popup class in t ...

Smooth animation is not being achieved with the Jquery dlmenu

I have implemented a multi-level navigation menu using a demo of the jquery dlmenu plugin v1.0.2. Although most of the functions are working smoothly, the CSS3 menu navigation lacks the fluidity of the jQuery left/right sliding effect. Is there a way to ...

Interactive Show Map with Autocompletion Feature

I attempted to implement autocompletion for my application and integrate it with Google Maps, but I'm encountering issues. The code for autocompletion is located in a separate JavaScript file called autocomplete.js. Since I already have a Google Map ...

Is there a way for me to choose the item from the search dropdown so that it fills in the search input field automatically?

Upon typing a word into the search input field, a list of suggestions will appear below. https://i.sstatic.net/etOBI.png Is there a way for me to select a word from the list like Maine (ME) and have it automatically fill the search input field? What chan ...

Creating a custom blockquote style for a WordPress Twenty Fifteen child theme

Currently, I am creating a new child theme for Twenty Fifteen completely from scratch. The one area I am struggling with is customizing the appearance of the blockquote using CSS. Here is an example of the custom CSS I have added to the blockquotes within ...

Display div content depending on the clicked ID in AngularJS

Unique Header Links HTML <ul ng-controller="pageRouteCtrl"> <li ui-sref-active="active"> <a ui-sref="home" class="" ng-click="getPageId('live-view')">LIVE</a> </li> <li> <a ng-clic ...

Icon alignment to wrapped text width has been successfully achieved with the implementation of Flexbox onto a single

I am facing an issue with text wrapping within a flexbox. I want the width of the flex item to always match the length of the wrapped text so that an icon placed next to the item stays adjacent to the text. However, due to text wrapping, there is a gap bet ...

The div smoothly descended from the top of the page to the center under the control of jQuery

I am trying to implement a feature where a div slides down from the top of the page to the center when a button is clicked. However, my current code seems to be causing the div to slide from the bottom instead of the top. Ideally, I want the div to slide ...

How can I eliminate the empty spaces surrounding an image?

How can I remove the extra space around an image that is placed inside a bootstrap column? On the desktop version, I was able to solve the issue by setting -1rem margins on the left and right. I tried adjusting the body margin and padding to 0, as well as ...

How can I navigate to a user profile page and access the specific data of the currently logged-in user using Django?

Progress on my small project was smooth until I hit a roadblock. I am currently facing an issue with routing to the profile page. Here is the workflow of my website: 1) User signs up and is redirected to the login screen upon successful registration. 2) U ...

Is there a more optimized CSS approach for this layout?

I attempted to create this layout using only CSS (no JavaScript, etc.) within an existing HTML page (without altering the HTML code). Unfortunately, I couldn't achieve all the positions that I needed. Let's see if anyone has a better idea. Thanks ...

Adjust the height for just one md-tab

Looking to find a way to set the height of the content within an <md-tab> element to be 100% in a flexible manner. For example, consider the following structure: <body> <md-content> <md-tabs> <md-tab label= ...