Is there a way to make my flex containers wrap to a new line when they overflow?

I'm facing an issue on my website where the search results are displayed in card format. However, when there are multiple results, instead of overflowing to the next line, the cards stay on the same line and shrink in size, making the content inside them look unappealing. It ends up looking like this: https://i.sstatic.net/7NJ2m.png.

Here is the code for the div-card:

<div class="card">
 <a href="#">
  <div class="image">
   <div class="title">

   </div>
  </div>
 </a>
 <div class="description">
  <h5>Title</h5>
  <p>Description</p>
 </div>
</div>

And the CSS for the card div (the image and description div css are omitted):

.card
{
  height:18em;
  width:14em;
  margin: 10px;
  display: flex;
  flex-wrap: wrap;
  flex-direction:column;
  position:relative;
  border-radius:16px;
  overflow:hidden;
  box-shadow:  15px 15px 27px #e1e1e3, -15px -15px 27px #ffffff;
}

Despite using the flex and flex-wrap: wrap properties, the divs do not wrap as expected. I have tried other solutions like display: inline, display: inline-block, and float: left without success. Any help in resolving this issue would be greatly appreciated, as the search results cannot be manually adjusted for line breaks.

Thank you!

Answer №1

One issue is that you are applying flex to a single card instead of the container div. To properly utilize flexbox, the container div housing all search result cards should have the flex properties. If we consider this scenario:

<div class="container">
    <item1 class="card">
    <item2 class="card">
    <item3 class="card">
    <item4 class="card">
</div>

You should implement the following CSS:

.container{
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    width: <set as needed, optional>;
    ....add any other desired properties
}

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

Leveraging a unique CSS stylesheet in conjunction with react bootstrap and webpack for enhanced

I am attempting to integrate React with this theme (), and have replaced the homepage/node_modules/bootstrap files with the ones provided. However, the website is still pulling styles from the original CSS files. Any suggestions on how to resolve this issu ...

Is there a way to mimic this type of scrolling effect?

Upon visiting this website, it is evident that the entire interface has been constructed with React. The scrolling experience on this site is exceptionally smooth, although it may feel slightly more substantial than a typical scroll. After researching onli ...

Defining the style class for a nested Angular 2 component

Located inside my.component.html <nested-component [class]="nestedClass"></nested-component> Now, when wanting to utilize my component, both style classes need to be specified: <my-component class="my-component-style" nestedClass="nested- ...

design facebook type box scroll bar

After extensively searching through various stackoverflow answers in an attempt to change the CSS for a Facebook likebox scrollbar, I have had no success. Below is the code that I am currently using: <div id="fb-root"></div> <script>(fun ...

Firefox does not support padding-top in pseudo elements, unlike Chrome and Safari which do

I am aiming to create three square boxes that adjust their size based on the browser's dimensions. Each box will contain only one line of text, so I plan to use padding to fill any extra space. My website utilizes flexbox, and I initially thought I h ...

I am unable to view the entire HTML element

i have a pair of div elements first one : text-logo .text-logo { width: 250px; height: 60px; margin: auto; border: 2px solid #07a2a0; border-radius: 15px 50px 15px 50px; margin-top: 100px; ...

Dynamic gallery with customizable features (HTML/CSS)

Seeking guidance on creating a seamless html/css gallery without any spacing between each gallery element. All elements are identical in size, housed as list items within a ul inside a div. Media queries have been established to adjust site and image siz ...

Shift the inline form towards the right within the navigation bar

I have the code located at this link. How can I align the inline form to the right? I am using Bootstrap 4 and have tried using the float-right class, but it doesn't seem to be working. Is there something I am missing here? <!DOCTYPE html> < ...

Error with an absolutely positioned element within a link in the Firefox browser

I'm experimenting with a unique effect for my links that involves making it look like the upper left corner has been bitten off. To achieve this, I am using absolute positioning of a square element with the same background color as the link itself. W ...

What is the best way to align the items in my navigation bar to the center?

I'm having trouble getting my navbar buttons to appear in the center of the navigation bar. No matter what I try, they only seem to align to the left or right. Can anyone help me figure out how to center them? Here's the CSS code I'm working ...

When hovering over a hyperlink, an image appears but I want to adjust the image's position in relation to each link

I have a unique feature on my website where text hyperlinks reveal small thumbnail images when hovered over. This concept was inspired by an example I found on this page. I initially implemented the code from a post on Stack Overflow titled Display Image O ...

Is there a way in CSS to apply multiple colors to individual letters within a word?

Is it possible to add random colors to every pixel of a letter or multiple colors to a letter using CSS? Check out this example. ...

The rounded corners border radius is not displaying when printing

After reviewing a helpful article on the topic from this link, I am still struggling to understand why my border-radius is not showing up when printing. The border-radius properties display correctly in the browser, but fail to print as expected. Here is ...

How can one easily display overflowing text when hovering over it?

My issue involves a p element that could potentially have lengthy text (I've used overflow: hidden; white-space: nowrap; text-overflow: ellipsis;). I want the text to appear as a floating link next to the cursor when hovering over the paragraph. Is th ...

What method can I use to ensure that the sidebar stays fixed at a particular div as the user continues to scroll down the

Is there a way to automatically fix the sidebar once the user scrolls down and hits the top of the .Section2? Currently, I have to manually enter a threshold number which can be problematic due to varying positions across browsers and systems. Fiddle htt ...

The slideshow element on my website is not positioning itself behind the fixed header element

I have a slideshow on my homepage that is not moving behind the fixed header when scrolling down, although it does correctly on all other pages of the website. Below is the HTML code: <body> <div id="wrapperfull"> <div id="head ...

Tips on getting your card to stay at the top

Screenshot of webpage HTML (EJS): In the HTML file, look for the section after <%- include("navbar.ejs") -%> inside the body tag. The ".cardholder" contains "anime-card" templates (card.ejs). The first and last div within ".cardholder" are ...

Tips for aligning navigation bar items to the right side

Seeking help with positioning the logo on the left and navigation items on the right using Bootstrap classes, while maintaining responsiveness. Click here for sample image 1 Check out the navbar layout <!-- Logo --> <a class="nav ...

unable to display picture on puggy

Check out the code snippet below: <!DOCTYPE html> <html lang="en> <head> <meta charset="UTF-8> <title>Home Page</title> </head> <body> <img src="resources/mainlogo.png" style="width:304px;height:2 ...

Add additional text using the ::after pseudo-element exclusively for a particular class

Here is the HTML code snippet I am currently working with: <style> p::after { content: "%"; } </style> <div class="counter-box"> <p data-value="185">100</p> </div> At present, my CSS applies text injection to ...