Tips for creating a CSS layout with two columns using the flex property

I'm having trouble getting my images to display in 2 columns within the container div. Right now, they are only showing up in a single column with an empty space beside them, as you can see in the preview image.

html

    <div class="container">
            <div class="box">
                <img v-for="(backgroundCover, index) in backgroundCovers" :key="index" :src="backgroundCover"
                    :alt="'Random Image ' + index" />
            </div>
        </div>

css

    .container {
    width: 100%;
    margin: 10rpx 30rpx 0;
    display: flex;
    flex-wrap: wrap;
}

.box {
    max-width: 300rpx;
    min-height: auto;
    padding: 10rpx;
    margin-bottom: 20px;
}

.box img {
    border-radius: 7%;
    max-width: 100%;
    height: auto;
    display: block;
}

Check out the preview here

Answer №1

Have you considered using pixels (px) instead of responsive pixels (rpx) and giving it another shot? I tested your code with px and it worked flawlessly.

Answer №2

It has been some time, but I have finally found the solution to this problem.

CSS


.container {
    position: relative;
    display: flex;
    margin: 0px 15px 0px 15px;
    min-height: calc(100vh - 140px);
}

.box {
    width: 100%;
    columns: 2;
    column-gap: 40px;
    padding-top: 15px;
}

.box-cells {
    padding-bottom: 40px;
}

.box img {
    border-radius: 15px;
    width: 100%;
}

HTML

<div class="container">
            <div class="box">
                <div class="box-cells" v-for="(backgroundCover, index) in backgroundCovers" :key="index">
                    <div>
                        <img :src="backgroundCover" mode='widthFix' alt="N/A img" />
                    </div>
                </div>
            </div>
        </div>

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

Updating Bootstrap Indicators with jQuery on Click Event

Unfortunately, I am unable to share an image due to limited internet data. My goal is to switch each image to its sprite equivalent. There are three list items that I'm struggling to change because they each have two classes that need to be updated. ...

Extracting a parameter from a URL using C#

Imagine having a URL such as http://google.com/index.php?first=asd&second=mnb&third=lkj What is the method to extract the second value (mnb) using C#? ...

How come my div doesn't stick together with the other div while moving?

I am trying to figure out how to make the blue "shield" div cover the red "button" div after 3 clicks successfully. It seems like no matter what I do, the positioning is always off. I've played around with the randomplace variable, but nothing seems t ...

Ways to conceal components upon clicking a different element

Struggling to make this jQuery function properly. I have a form with all fields contained in a div.form-group. The subscribe button is identified by the id subscribe. I'm aiming to hide the form fields when clicked, but my JavaScript doesn't see ...

Whenever I adjust the size of the div tag, it automatically shifts to the left and loses its responsiveness on mobile devices

This custom class has been created to adjust the size of the div tag and add margins in order to center the elements within the div. .adjust-width { width: 900px; position: center; margin-top: 50px; margin-bottom: 100px; margin-right: 150px; ...

Tips for preventing automatic zoom on mobile devices

Check out this link for the test: The current layout of the site is exactly how I want it to be presented. However, I am facing an issue where if I set the viewport meta tag to <meta name="viewport" content="width=device-width, initial-scale=1"> i ...

Safari does not support SVG fill pattern, unlike Firefox and Chrome

Having an issue with Safari 6.1.5 not displaying a pattern in an SVG rectangle. After simplifying the code, here is the test case: <html> <head> <style> .patterned { fill: url("#myid") none; stroke:blue} ...

Why are my menu and title shifting as I adjust the page size?

I'm having trouble finalizing my menu and headings. Whenever I resize the browser window, they shift to the right instead of staying centered as I want them to. I would really appreciate any help with this. Below is the HTML and CSS code. var slide ...

Is it possible to trigger a click event exclusively on a parent element?

One feature I'm trying to implement in my app is the ability to click on an item, such as changing the background color or text, and have a modal pop up with a color picker to customize the color of that specific item. However, I've run into an i ...

Convert JavaScript back into an HTML attribute

Is there a way to include a JavaScript code in an HTML attribute like shown below? <div class="xx" animation="yy" animate-duration="<script>Code goes here<script>" ...> </div> I'm struggling to figure it out, is there a solut ...

Tips for transforming an HTML website into a WordPress site

After choosing the default WordPress theme, for example twenty thirteen, and customizing it with my own CSS, I was able to achieve the look I wanted for my header and footer. However, I encountered difficulties when creating pages as the default CSS of t ...

Increasing the size of the td element when including a new row

Here is an html page example that I am working with: However, when I add a new row beneath the existing row that contains a div block and form within it, I notice that the td tag in the first row expands in width, as depicted in the image below. Below is ...

Generating a vertical line right in the middle of the list item

I have recently designed an HTML page featuring a list of links using ul and li elements, with a customized background color for each li. Now, I am looking to add vertical lines next to the li items. When attempting to insert an image, my output looks lik ...

JSON failing to show all values sent as a string

In a div element there is a table with 3 rows, a textarea, and a button. The JSON data populates the first 3 rows correctly but the textarea remains blank. My goal is to display the previous record from the database in the textarea. function ChangeLoadin ...

When additional elements follow, the button ceases to function properly in JavaScript

I am working on creating a text-based idle game that involves multiple buttons and text around them. However, I have encountered an issue where the functionality stops working when I try to add text after the "Work" button. The callback function is no lon ...

Utilizing Javascript or jQuery to showcase Facebook Events directly on a website

I have been working with the facebook SDK for javascript and successfully retrieved data in the browser console using sample code. index.html:377 API response Object {data: Array[7], paging: Object} data: Array[7] 0: Object description: "This is just an ...

Apply a specific class only when the user scrolls within the range of 200px to 300px

Is it possible to dynamically add a class to a div element based on the user's scrolling behavior? For example, I would like to add a class when the user scrolls 200px down the page, and then remove it when they scroll 300px down. Similarly, I want to ...

Position the button at the bottom of the card using Bootstrap

While exploring a Bootstrap example utilizing the card-deck and card classes (Pricing example), I pondered over how to align buttons correctly when one list has fewer items than others. https://i.sstatic.net/IGN7K.png I aim to vertically align all button ...

How can I show/hide a div based on checkbox click on my website? It works in jsFiddle, but not on my actual site. Any suggestions?

Is there a way to show or hide a div based on a checkbox click? I've got it working in jsFiddle, but for some reason, it's not functioning properly on my website. Any thoughts on how to fix this? My goal is to offer multiple payment methods (cre ...

Angular testing does not recognize the variable

I'm currently testing an Angular app in Protractor and I'm puzzled by a certain issue that keeps occurring. Here's the test code snippet: beforeEach(function() { browser.get('http://localhost:8080/#/'); ... ...