Issue with arranging cards in a grid when utilizing v-for alongside bootstrap

Just starting out with vuejs and attempting to create a grid by looping through objects using bootstrap classes. However, I'm running into an issue where the cards are not forming a grid as expected when utilizing the col classes.

Below is the code for the component:

<template>
  <div class="row">
    <div class="col-md-6 col-lg-4">
      <div class="card">
        <div class="card-header card-head-color">
          NAME <small>(Price: PRICE)</small>
        </div>
        <div class="card-body">
          <div class="float-left">
            <input type="number" class="form-control" placeholder="Quantity" />
          </div>
          <button class="btn btn-success float-right">Buy</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Stock",
};
</script>

<style scoped>
.card-head-color {
  background-color: #54db47;
  opacity: 0.7;
}
</style>

https://i.sstatic.net/OaPsz.png

The issue persists where all cards are displaying in a single column instead of a grid layout.

This is the parent component where it is called:-

<template>
  <div>
    <app-stock v-for="stock in stocks" :key="stock.id"> </app-stock>
  </div>
</template>

<script>
import Stock from "@/components/stock/Stock";
export default {
  name: "Stocks",
  data() {
    return {
      stocks: [
        {
          id: 1,
          name: "BMW",
          price: 100,
        },
        {
          id: 2,
          name: "Google",
          price: 200,
        },
        {
          id: 3,
          name: "Apple",
          price: 250,
        },
        {
          id: 4,
          name: "Twitter",
          price: 10,
        },
      ],
    };
  },
  components: {
    appStock: Stock,
  },
};
</script>

<style scoped></style>

In need of assistance in getting the cards to properly form a grid layout. Any help would be greatly appreciated.

Answer №1

When you iterate through the row, each row element contains only one card, resulting in each column taking up the entire width...

If you want to display multiple cards next to each other, consider making the <row> element a wrapper for your v-for loop. Here's an example:

In your parent component:

<template>
  <div id="app">
      <b-container>
          <b-row>
              <app-stock v-for="stock in stocks" :key="stock.id"></app-stock>
          </b-row>
      </b-container>
  </div>
</template>

And in the child component:

<template>
   <b-col class="col-md-6 col-lg-4">
       <div class="card">
           <div class="card-header card-head-color">
               NAME <small>(Price: PRICE)</small>
           </div>
           <div class="card-body">
               <div class="float-left">
                <input type="number" class="form-control" placeholder="Quantity"/>
            </div>
            <button class="btn btn-success float-right">Buy</button>
        </div>
    </div>
</b-col>

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

How can I limit the Bootstrap datetimepicker to only allow past and present dates?

I am trying to implement a date time picker on my website, but I need help restricting future dates. Specifically, I want to prevent users from selecting dates that are after the current date. Code Sample $('.datetimepicker').datetimepicke ...

Alternative image loading in a figure element

I'm currently in the process of putting together an image gallery using Angular 4.3.0, where images are displayed as background images within figure elements rather than img tags. The images are initially resized to smaller dimensions before being use ...

Combining Python strings

I'm trying to understand the distinction between two statements. I need to display a variable in a <p> HTML tag. Both statements achieve the same outcome, but one is causing an error. The first statement that functions correctly: out += "</ ...

Checkbox input with alphabetical ordering

I am currently facing an issue with a form that has checkboxes, but the text is not in alphabetical order. While there are plenty of examples for lists, finding examples for checkboxes has been challenging. http://jsfiddle.net/fG9qm/ <form> < ...

Utilizing jQuery to toggle nested divs within identical parent divs when they contain more than three elements using the :nth-child selector

Within my HTML markup, I have created two parent div elements that are exactly the same but contain different content. My goal is to have a functionality where if a parent div has more than 3 child div elements, a "show more" text will be displayed at the ...

"Comparison: Utilizing HTML5 Video Player with IE8 Embed Fallback versus Implementing Fixed

This dilemma has me at my wit's end. In an HTML5 Video element, I've included an mp4, ogg, and an embedded mp4 fallback. However, on the embed fallback in IE8, all my attempts to position the fixed element (#fixed) above it with z-indexing have f ...

Remove the initial DIV element from the HTML code

I have created a unique chat interface by combining JScript, php, and jquery. The chat messages are saved in an HTML document that gets displayed in the text area. Each user input message is contained within its individual div tag: <div>Message</ ...

What method can I use in webpage coding to achieve this special highlight effect, and what is the official term for it?

Need help figuring out how to make an icon change from blue to white when selected. I've searched through Bootstrap, CSS, and HTML, but haven't found the solution yet. Any suggestions would be appreciated! https://i.stack.imgur.com/RK1PD.png ...

What is the best way to prevent a draggable div from moving past the edge of the viewport?

My situation involves a draggable div that functions as a popup window when a specific button is clicked. However, I noticed that dragging the div to the end of the viewport allows me to drag it out of the visible area, causing the body of the page to expa ...

Swap the existing div with a fresh div using jQuery or JavaScript

Seeking a straightforward method to swap out a div with a different div, ensuring cross-browser compatibility with JavaScript or jQuery. Below is a code snippet to demonstrate. The goal is to replace "myDiv-B" with a new div: <div id="myDiv-C">{% in ...

What could be causing the flexbox code to not take effect and the text to refuse wrapping?

I've been utilizing flexbox to style my content, and it worked seamlessly on the first three divs. However, when I attempted to apply the same styling to the fourth one, it didn't quite work out as planned. Despite trying options like flex-wrap t ...

What is the reason this straightforward regex functions perfectly in all cases, except for when applied to the html5

This particular HTML input turns red to signify that the pattern has not matched when the value in the input field is "1". var newInput = document.createElement ('input'); newInput.pattern = '^\d+\.?\d*$'; document.getEl ...

Attempting to showcase the text within an <a> element on a <canvas> element while ensuring there are no noticeable visual distinctions

Imagine having this snippet of code on a webpage: elit ac <a href="http://www.ducksanddos/bh.php" id='link'>Hello world!</a> nunc Now, picture wanting to replace the <a> tag with a <canvas> element that displays the same ...

Ensure that radio buttons are evenly aligned both vertically and horizontally within a flexbox layout

I am attempting to align Radio buttons both vertically and horizontally within a flexbox layout. I have made an attempt so far, but unfortunately, the buttons are not aligning properly. Here is the code snippet: <div class="d-flex flex-column justify-c ...

The PHP on server could not be loaded by Ajax

Trying to establish a PHP connection, encountering an error and seeking assistance. The error message displayed is as follows: { "readyState": 0, "status": 0, "statusText": "NetworkError: Failed to execute 'send' on 'XMLHttpReq ...

Activating/Deactivating a button with just a press

In my SQL data display, each row has an "Add To Zip" button that is initially enabled. I want to disable the button in the current row when it's clicked and later re-enable them using a different PHP file. What's the best way to achieve this with ...

Leveraging jQuery functions with dynamically generated DOM elements in JavaScript

On my website, I have a button that dynamically generates a dropdown menu, a textfield, and two buttons when clicked. The purpose of the textfield is to track the quantity selected, while the two buttons allow users to increase or decrease the value by 1. ...

Can a nodeJS script be written to automate selecting options and filling out forms in HTML?

Greetings everyone, I am new here so please excuse me if my formatting is not up to par. Currently, I am tackling a project for an internship and after some extensive research, I am stumped on how to automate certain reports in the next phase. In summary ...

I am having trouble deactivating an HTML button using my JavaScript function

I have been working on a feature where a button in HTML is supposed to be disabled until a specific textbox is filled out. Once the textbox has content, the button should become enabled and save the user's name along with their score from a previous g ...

Curved edges achieved without the need for relative positioning

Can anyone help me with a specific code snippet to achieve rounded corners for this page ? Currently, I am using the PIE.htc file which only works when I declare position:relative; throughout the layout, causing disruptions. Is there a code workaround that ...