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

Column reverse flex-direction is functioning correctly, however, it is imperative that it does not automatically scroll to the bottom

I have a Flexbox set up where I need the contents to display in reverse order. Everything is working well, but the list has many items and the newest ones are appearing at the top. Currently, the Flexbox automatically scrolls to the bottom, but I want it t ...

Is the image flickering non-stop when the button is pressed?

Every time I push the button, the image on the HTML 5 canvas flickers. After investigating, it seems like the issue might be related to the ctx.clearRect(0,0,100,500) function. Any suggestions on how to fix this problem? I'm currently working on anim ...

Utilizing Sessions Across Several PHP Forms

Hey there! I've got a query for you. When you kick off your PHP code with session_start(), do you need to keep adding the prior variables on subsequent form pages? I'm contemplating using the session() function for my GYM Sign UP Webpage. The f ...

Choosing several buttons in typescript is a skill that every programmer must possess

I need help with selecting multiple buttons in TypeScript. The code I tried doesn't seem to be working, so how can I achieve this? var input = document.getElementById('input'); var result = document.getElementById('result'); v ...

Resizing a scrollable list using React Refs and UseLayoutEffect

Essentially, my issue stems from having a scrollable list with a set maximum height of '100vh'. I also have a detail card beside the list that contains accordion components. When one of these accordions is expanded, it increases the height of the ...

The execution of the function halts as soon as the player emerges victorious

In my attempt to create a basic game where players compete to click their designated button faster to reach 100%, I am in need of assistance with implementing a logic that determines the winner once one player reaches or exceeds 100. Essentially, I want ...

The arrangement of pictures on a card

I decided to tweak the original concept by placing the images inside a Bootstrap card. However, the end result is that the images appear to be floating. https://i.stack.imgur.com/Uf721.png Any suggestions on how to make them fit nicely within the card? ...

An interesting approach to utilizing toggle functionality in JQuery is by incorporating a feature that automatically closes the div when

Currently, I am utilizing JQuery's toggle function to slide a ul li element. However, my desired functionality is for the div to close if someone clicks outside of it (anywhere on the page) while it is in the toggle Down condition. Below, you'll ...

Passing image source from parent component to child component in Vue.js

I encountered an issue where I stored the image file name in a variable within the parent component and passed it to the child component using props. However, despite this setup, the child element is not displaying the image as expected. Here is the data ...

Link the html button with the php code in order to perform a specific action

I am looking to link my HTML code with PHP in order to achieve the following functionality: 1. Create a cookie that prevents a specific message from being displayed again when a certain button is clicked. 2. Hide messages using CSS after the button clic ...

Discover an improved method for creating a custom list style using Unicode Numbers in CSS

I am interested in creating a unique list type using Khmer Unicode Numbers ១ ២ ៣.. in a precise order. To achieve this, I attempted to utilize CSS pseudo-classes li:nth-child(1) li:nth-child(2) li:nth-child(3).. defined in my stylesheet as follows: ...

How can you use C# code to control the visibility of a table row in HTML?

I am trying to display or hide a table row based on the current month using DateTime.Now.Month in my HTML code, but I can't seem to remember the correct syntax. The code I have tried is not working as expected. Can anyone help me with the correct synt ...

Hide the scrollbars on the sidebar

I'm attempting to recreate a sleek scrollbar that caught my eye on the website . To achieve this, I need to have a screen larger than 955px in order to display the sidebar. However, when my sidebar overflows in the y direction, it causes an additional ...

How can the background of a div be altered when text is typed into an input field?

I need help with the following code. I want to be able to change the background color of a div with the class "target_bg" from red (default) to green every time someone enters or types text into the input field. <div class="target_bg"></div> & ...

Streamlining all icons to a single downward rotation

I am currently managing a large table of "auditpoints", some of which are designated as "automated". When an auditpoint is automated, it is marked with a gear icon in the row. However, each row also receives two other icons: a pencil and a toggle button. W ...

Create a custom CSS style to replace the default jQuery hide() function

HTML <div class="adm-input" <?php if(!empty($admin_fee) || $admin_fee != "") echo "style='display:block'"; ?> id="fees-input"> <label>Admission Fees(<i class="fa fa-inr"></i>)</label> <div class="in ...

Stylized search input inspired by Pinterest with a bubbly design

When it comes to my search bar, I want the user's entered keywords to be displayed within a bubble that has a delete option when they press space to add another keyword. This functionality is similar to what Pinterest does with their search bar, as de ...

What is the best way to instruct npm to generate a .min.css file from scss?

Currently, I have setup a process to automatically compile CSS from SCSS using a JSON script. However, the issue is that the ".min" suffix is being removed during this compilation. Here is the output from the terminal displaying the script I am running and ...

The height of the textarea is too excessive

Just a quick question - in my HTML, I have a simple textarea nested within the body tags. Within my JavaScript, I am using jQuery to ensure that the body element is dynamically resized to match the height of the window: $(function() { $("body").heigh ...

Exploring the potential of Framework7 in Single Page Applications: optimizing performance by preloading

I'm currently working on developing a web application using Framework7. Framework7 offers routing APIs for navigating between HTML pages. It seems that the pages are loaded dynamically through AJAX requests. I am curious if it is possible to preload ...