How come my flexbox items are not aligning in a row when using v-for?

I have designed a component that acts as a container for multiple items, using v-for to display four of these containers on my page. However, they are currently only shown in a single column layout and I need them to be displayed in two columns per row on desktop and in a single column on mobile devices. I already have a footer and background setup without using flexbox, so I want to make the necessary changes to the containers without affecting other components.

App.Vue code:

<template>
  <div id="app">
    <Background />
    <div v-for="cliente in clientes" :key="cliente.id">
      <Steps :cliente="cliente"/>
    </div>
    <Footer/>
  </div>
</template>

<script>
import Steps from './components/Steps.vue'
import Footer from './components/Footer2.vue'
import Background from './components/Background.vue'
export default {
  name: 'App',
  components: {
    Steps,
    Background,
    Footer
  },
  data(){
      return{
          clientes:[
        {
            id: 1,
            name:"Detalhes da Partida"
        },
        {
            id: 2,
            name:"Jogadores"
        },
        {
            id: 3,
            name:"Evidência da Partida"
        },
        {
            id: 4,
            name:"Mensagem: (opcional)"
        }

      ]
      }
  }
}
</script>

<style>
html, body {
    margin: 0;
    padding: 0;
    box-sizing: border-box; 
    background-color: #3B3B3B;
}

</style>

Component code:

<template> 
    <section class="flex">
      <div>
        <p class="teste">{{cliente.id}}. {{cliente.name}}</p>
      </div>
  </section>
</template>

<script>
export default {
  name: 'Steps',
  props:{
      cliente: Object
  }
}
</script>

<style>
*{
    margin: 0;
    padding: 0;
}
.teste{
  color: #FFF;
  border-bottom: 1px solid #707070;
  padding: .5em .5em 0;
}
.flex {
  display: flex;
  flex-wrap: wrap;
  max-width: 32em;
  height: 30em;
  background-color: #232323;
  margin: 1em auto;

}
.flex > div {
  flex: 1 1 100px;
}
</style>

Answer №1

Your usage of flexbox is incorrect. The class flexbox should be added to the container that wraps the element with v-for. This will ensure that all elements generated by v-for become flex-items.

View CODESANDBOX

App.vue

<section class="flex">
      <div v-for="cliente in this.clientes" :key="cliente.id">
        <Steps :cliente="cliente" />
      </div>
</section>

Steps.vue

<template>
  <div>
    <p class="teste">{{ cliente.id }}. {{ cliente.name }}</p>
  </div>
</template>

To create a two-column layout for medium screens and above, and a single column layout for mobile devices, add a media query.

Add the following to App.vue -> style:

.flex {
  display: flex;
  flex-wrap: wrap;
  max-width: 32em;
  height: 30em;
  background-color: #232323;
  margin: 1em auto;
}
.flex > div {
  flex: 50%;
}

@media only screen and (max-width: 768px) {
  .flex > div {
    flex: 100%;
  }
}

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

Connect and interact with others through the Share Dialogues feature in the

Update - Edit I'm just starting to explore the concept of share dialogues and I want to integrate it into my website. On my site, there is a reaction timer game that shows the user's reaction time in seconds in a modal popup. I want users to be ...

Close any other panel when one is selected in a loop

I am experiencing difficulty with a series of menus that are causing other panels to hide when one is clicked and active. @{int i = 0;} @foreach (var levelOne in Model.MenuLevelOne) { <div class="panel-group" id="accordio ...

Error occurred during the authentication process while attempting to upload a file to Firebase storage

While attempting to upload a small file to Firebase storage using Vue.js, I keep encountering a QUOTA_EXCEEDED error. It seems there are an unusually high number of calls to https://securetoken.googleapis.com/v1/token?key=<SomeLongString>. Despite th ...

Is it possible to create a reusable TypeScript interface for an array of functions?

Currently working with Vue and Typescript, I'm exploring different ways to describe types for an array of functions. In my current code, I have the following setup. Is there a way I could define an interface called formRules instead of repeatedly decl ...

Rearrange the first division to the second division in a responsive manner

.box { display: block; width: 200px; height: 200px; padding: 20px; background: black; } .class1 { position: relative; color: red; } .class2 { position: relative; color: red; } <div class="box"> <div class="class1"> Th ...

Display the Bootstrap dropdown menu on the right-hand side

I am currently working on a dropdown menu and I would like the dropdown items to be displayed on the right side. The functionality is working, but there seems to be an issue where the dropdown menu is not fully visible. The dropdown menu is located within ...

Using jQuery UI to trigger Highlight/Error animations

Apologies if this question seems obvious, but I can't seem to find a clear answer anywhere... Is there a way to add a highlight/error message similar to the ones on the bottom right of this page: http://jqueryui.com/themeroller/ by simply using a jQu ...

Limiting the display of JSON data on a webpage using jQuery

I have a code snippet on my website that displays JSON data on an HTML page. The issue is that there is a large amount of data in the JSON file. How can I limit the number of movies (data) being displayed to just 5? function actors(actors) { return ` ...

How can you effectively pass props to a Vuejs Component that is rendered by a Router?

I am new to Vuejs, so I apologize if this is a beginner question. I have added a router to my App and I want to display data from my main App in my Components templates, but it doesn't seem to be working. Here is my current setup: Vue.use(VueRouter ...

CSS Stylelint rule to detect the 'missing selector' issue

My current process involves using stylelint to identify any CSS errors before building and deploying our site. However, a recent commit includes code that fails the CSS parser/minifier but passes stylelint validation. .example-class , /*.example-class-two ...

Is there a significant difference between having 20 components or just one with v-if on my page?

Within the realm of Vue/NuxtJS 2 or 3, I am facing a specific scenario. Currently, I have modal components nested within TableViewRow components. These modals are utilized to display an edit form for the row's data. Essentially, each modal component i ...

In my PHP loop, I am creating radio buttons and I only want one of them to be selected at a time

How can I ensure that only one radio button is selected out of the 99 radio buttons generated in this for loop? for($x = 2; $x <= 101; $x++){ $out .= "<img src='/img/channel_icons/".$icons[$x]."' class='ch ...

Determine whether a child element is missing a certain class

I am currently investigating whether a child element lacks a specific class. The elements in question are: <g id="note1"> <path id="Barline1" d="M55.837,19.278h0.249c0.11,0,0.199,0.089,0.199,0.199V40.56c0,0.11-0.089,0.199-0.199,0.199h-0.249c ...

Guide to positioning a bootstrap navbar toggle button to the left or right of the logo

My React app includes a bootstrap navbar with the following code - <nav className="navbar navbar-default navbar-expand-sm navbar-light bg-light"> <div className="container-fluid"> <div className="navba ...

Path of the HTML5 database in Blackberry WebWorks

When referencing the Blackberry WebWorks API guide for HTML5 Database, I came across a crucial note: Note: For 5.x devices, an SD card is a necessary storage method for databases. To initialize a database, you can use this code snippet: db = window.open ...

Capture all div elements from the table and store them in an array

Check out this code snippet that includes draggable divs and a droppable table: http://jsbin.com/exetuk/1/edit When dragging a div to the table, copies of the div with the class .draggable appear. I am looking to create an array with divs from the table ...

Transmitting the contents of $body in Mysql as table information, not as

Looking for a way to send MySQL database data via email using PHP Mailer. I have managed to send it as an attachment, but struggling to send it as a formatted body. When I try to use file_get_contents on 'displaywebpage.php', it only reads the HT ...

What is the best way to eliminate the horizontal line in the modal's body and footer?

How can I eliminate the horizontal lines from my modal? $(document).ready(function(){ $('#myModal').modal('show'); }); <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity= ...

The Javascript file seems to be unable to recognize the reference to an Angular directive

When working on my project, I encountered an issue with my EventController.js not recognizing the reference to ng-app="eventsApp" from app.js. I followed a tutorial on Pluralsight. Even though it works for the instructor, I keep seeing {{event.name}} inst ...

Saving data values for utilization in jQuery

Recently, I've come across a series of links structured like this: <a class="colorBox" href="#" title="#0676B3"></a> <a ... <a ... these links all have color values in the title attribute <a ... What I'm trying to do is uti ...