What is the best way to create a layout for Flexbox project boxes with three boxes per row?

My project cards are displaying in a single horizontal line and expanding infinitely to the right, rather than appearing in rows of three as intended. This causes them to extend outside the visible area in a long horizontal strip.

See the issue in action here:

https://jsfiddle.net/qk1pkkcd/2/

Here is the code for the project boxes:

<div class="card-container">
        <div class="card-top learn">
            <img class="card-top.create card-top" src="<%= Citybuilder.ProjectPic.url({@post.project_pic, @post}) %>" />
            <span class="project-type"><%= @post.project_location %></span>
            <div class="blur"></div>
        </div>
        <div class="content">
            <div class="details">
                <span>  </span>
                <span>...</span>
            </div>
            <div class="project-card-title">
                <%= @post.title %>
            </div>
            <div class="project-card-summary">
                <%= truncate @post.body, length: 80, separator: " " %>
            </div>
            <h3 class="house-divider-unicode">~</h3>
            <div style="text-align: center">
                <div class="project-card-done-so-far-one">1.
                    <%= @post.done_so_far_one_title %>
                </div>
                <div class="project-card-done-so-far-one">2.
                    <%= @post.done_so_far_two_title %>
                </div>
                <div class="project-card-done-so-far-one">3.
                    <%= @post.done_so_far_three_title %>
                </div>
            </div>

To render the posts correctly, use this snippet:

 <div class="center-wrap">
        <table id="posts" class="table posts flex-table-posts">
            <tbody>
                <%= for post <- @posts do %>
                    <%= render "_post_variants.html", conn: @conn, post: post, upvote: @upvotes[post.id], forks_count: @forks_count %>
                        <% end %>
            </tbody>
        </table>
    </div>

I tried setting the width of the card container to 1/3:

.card-container {
    font-family: "Open Sans", sans-serif;
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
    display: inline-block;
    min-width: 24.92em; 
    height: auto;
    margin-right: 2em;
    margin-bottom: 2em;
    border-radius: 0.5em;
    background-color: #fff;
    box-shadow: 6px 6px 6px rgba(0, 0, 0, 0.3);
    position: relative;
    padding-bottom: 3em;
    width: calc(100% * (1/3));
       flex-grow: 1;
}

.flex-parent-container {
    display: flex;
     flex-wrap:wrap;
}

However, the boxes continue to stack horizontally instead of appearing in rows of three as expected.

Answer №1

Make sure to add the class flexy to the wrapper div and designate it as a flex container

.flexy{
    display:flex;
    flex-wrap:wrap;
}

Additionally, adjust the width to ensure it fits perfectly on the page. Feel free to check out the codepen link: https://codepen.io/Rookie_sai/pen/yzogvz

I hope this information is helpful!

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

Preventing the collapse of the right column in a 2-column layout with Bootstrap 3

I've recently begun exploring Bootstrap and am attempting to achieve the following: (Left column - larger) Heading Heading 2 Heading Image Heading Image Heading Address (Right column - smaller) Heading Paragraph List items My issue ...

Creating a checklist using HTML and CSS can be achieved by utilizing the <span> element and

I'm having trouble changing the color of a span box to red when I focus on a link. The span successfully changes color when activated, but nothing happens when I try to use the 'focus' pseudo-class. On click, different categories will displa ...

Comparison between UI Router and ngRoute for building single page applications

Embarking on a new Angular project, a single page app with anticipated complex views such as dialogs, wizards, popups, and loaders. The specific requirements are yet to be clarified. Should I embrace ui.router from the start? Or begin with ngRoute and tra ...

The external function in HTML Form's onsubmit attribute is failing to execute

My HTML Form has an onsubmit event that should call a validate() function. Everything works fine when the validate() function is inside a script tag at the end of the body tag. But if the validate() function is in an external JavaScript file, like in thi ...

Concealing subcategories within a responsive menu using jQuery

My website's responsive menu changes based on screen resolution, but I encountered an issue. On mobile viewports, the sub items in the menu are displayed by default. I want them to only appear when the parent item is clicked. Currently, clicking the p ...

Continue scrolling once you reach the fixed-positioned div

live demo html <div class="one"></div> <div class="two"></div> <div class="three"></div> <div class="four"></div> css .container{ margin: 0; padding: 0; ...

Adjusting the spacing between the logo and navbar in HTML code

I am struggling to understand why this issue keeps occurring: I have thoroughly checked for errors, attempted multiple solutions, yet the problem persists. Please assist body { margin: 0; padding: 0; } .logo { margin: 0; padding: 0; } ul { li ...

Incorporating a YouTube channel into mobile websites

While it's relatively easy to embed single YouTube videos in mobile pages with the help of Google, I'm still struggling with embedding a whole channel. The issue seems to revolve around the screen width, and my attempts at using JavaScript have n ...

Stylish CSS menu design

I am struggling to set up a top menu bar using float: left. How can I achieve the desired behavior for a top menu bar? The code snippet below demonstrates what I have tried so far: * { margin:0; padding: 0; } #menu { background-color: yell ...

Attempting to achieve the effect where the entire row of a table changes color when the mouse hovers

I'm attempting to create a gradient effect for an entire row in a table when the mouse hovers over any cell within that row. Despite using what I believe is the correct CSS code, nothing changes upon mouseover (even though the original gradient appear ...

Using HTML to create interactive table cells

I am looking to add functionality to make a cell in an HTML table clickable. When this action is triggered, I want a pop-up or window to appear with specific information. Below is my current HTML code: <table class="table1"> <thead> <tr ...

Transform your ordinary HTML select into a stylish span with this custom CSS class

I need help making a select element appear like a span under certain conditions. The CSS class I currently have works with input boxes, but not with dropdowns. Is there any advice on how to style the select element to look like a span without actually repl ...

Setting the size of a box using CSS in HTML pages

I am facing issues with resizing boxes. Below is the code snippet: <!DOCTYPE html> <html lang="en"> <head> <style> .wrapper { text-align: center; } #bubble { display: inline; -moz ...

Issues arise when the elements <html> and <body> fail to adhere to a 100

Lately, I've been struggling with various problems related to heights. I was able to resolve the height issues of certain elements using flex:auto and flex-shrink:0. However, I'm facing difficulties getting the HTML and Body tags to cooperate ( ...

"Concealing Querystrings in Node.js and AJAX: A Step-by-Step

I want to create a simple login form using the ajax Post method. However, I am having issues with the querystring still appearing in the URL. Can anyone help me resolve this issue? Thank you for any assistance! [ https://i.stack.imgur.com/R76O4.png http ...

Accordion border in Bootstrap should be applied to all items except the first one

I am currently implementing Bootstrap accordions in an Angular application and I am facing an issue where I want to have a colored border all around each accordion panel. The problem is that by default, Bootstrap removes the top border from all accordions ...

Creating a persistent gap BETWEEN li inline list items

I'm seeking a solution to create horizontal links using a list. I know that I need to apply the display: block property to the ul element and set display: inline for the li items. While there are several inquiries about maintaining a consistent width ...

My desire is to have the left image's position set as sticky

Currently, I am attempting to update the image positioning on this page for the T500 Smart Watch: I want it to look similar to how it appears here: Here is the CSS code I have experimented with: .storefront-full-width-content.single-product div.product ...

Is there a way I can edit this text on the backend page?

Currently, I am attempting to implement a scrolling text box on a front-end page that will display the content from a text file named "msg.txt". <div class="scroll-slow"> <?php echo file_get_contents('../msg.txt'); ?> </div> ...

Navigating through dropdown browser menus using VBA

I am looking to automate the process of looping through a dropdown list on a specific website and downloading the latest file for each entry. I have successfully opened the website and clicked the "submit" button, but I am struggling to find a solution to ...