Ways to organize divs in a layout resembling a partial table

While working on my e-commerce platform with vue.js, I noticed that my product listings are not aligning properly, as displayed in the image linked below.

https://i.sstatic.net/2FwaA.png

My goal is to achieve the desired layout illustrated in the image below.

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

Below is a section of the code snippet I am currently using:

<template>
   <div class="products">
      <div class="prod-container">
         <div class="bangles" v-for="product in products" v-bind:key="product.id" style="width: 16rem;">
            <ProductSlide class="slide" type="bangle" v-bind:product="product"/>
         </div>
      </div>
      </div>
   </div>
</template>

<script type="text/javascript">
   import ProductSlide from '@/components/productSlide.vue'
   export default {
      name: 'Bangles',
      components: {
         ProductSlide
      }
   }
<script>

<style type="text/css" scoped>
   .prod-container {
      margin-right: 5%;
   }
   .bangles {
      display: inline-flex;
      margin: 1%;
   }

   @media screen and (max-width:639px) {
      .bangles {
         margin-left: 25%;
      }
   }

   .products {
      margin-bottom: 5em;
   }
</style>

Various attempts have been made to adjust the position, display, and width parameters, but none have yielded the desired outcome so far.

Answer №1

If you're in a bit of a bind without a prototype, one solution could be utilizing CSS Grid. Check out this helpful guide: https://css-tricks.com/snippets/css/complete-guide-grid/

Here's an example of what your styles might resemble:

...
.bangles {
  display: grid;
  grid-gap: 1%;
  # establish a grid with 3 columns of equal width
  grid-template-columns: repeat(3, 1fr); 
}

Adjust the number of columns in your @media queries as needed.

Answer №2

I finally cracked it! After some trial and error, I discovered that removing the width attribute from the ProductSlide Tag resolved all my issues. If anyone has insights into why this happened, please share!

Check out my updated code snippet below:

<template>
<div class="products">
<div class="prod-container">
  <div class="bangles" v-for="product in products" v-bind:key="product.id">
    <ProductSlide class="slide" type="bangle" v-bind:product="product"/>
  </div>
</div>

</div>
</template>

<script type="text/javascript">
import ProductSlide from '@/components/productSlide.vue'
export default {
  name: 'Bangles',
  components: {
    ProductSlide
  }
}
<script>

<style type="text/css" scoped>
.slide {
    position: relative;
}

.prod-container {
    margin-left: 15%;
    display: inline-flex;
    flex-wrap: wrap;
}
.bangles {
    display: inline-flex;
    margin-top: 2%;
    float: left;
    vertical-align: top;
    }
@media screen and (max-width:639px) {
    .bangles {
        margin-left: 25%;
    }
}

.products {
   margin-bottom: 5em;
}

</style>

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

What are the steps for initializing a session in Vue.js with Django upon a successful login?

Upon successful login, I want to redirect to a page indicating success and also include a session. How can this be achieved? I am using HTML with Vue.js for the front end and Django for the back end. Below is my Vue.js script for the login: <script> ...

Input Form Label inexplicably rounded off at odd location

I've been utilizing Bootstrap to style my page, and I used the input form classes provided by Bootstrap to create this input field. However, upon loading the page, I noticed some strange rounding occurring between the label and the input space. http ...

Impress.js functions properly within a Vue component, however, the 'visibility:hidden;' style is not consistently overridden in standard HTML

Recently purchased a commercial license and attempting to follow the documentation, but encountering issues with getting the animation to function My setup includes Laravel 5.4 and Vue 2 <head> <link rel="stylesheet" href="/css/animate.min.cs ...

Div element failing to scroll with excessive content

I'm currently working on a modal using Mui Modal and I've encountered an issue. Everything seems to be functioning correctly until I add more items to the cart. When the minHeight exceeds 500, it stops at 100vh and only displays 5 items, even if ...

Adaptable layout - transitioning from a two-column design to a single-column layout

I'm facing an issue with two divs that are floated left to appear inline <div class==".container" style="width: 100%"> <div class="leftColumn" style="width: 50%; float:left"> test </div> <div class="rightColu ...

Having trouble getting a Chrome extension/jQuery to work on certain sites but not others? Attempting to trigger an event when a link is clicked

For three different websites, I have three separate js files. I want to mention that the manifest has the correct settings to make sure these files work on the right sites, but unfortunately, only one function of the extension (the most important one) is n ...

Create HTML email content from a dynamic table data containing date columns in SQL

I am presenting a dynamic table data below region 01-May-2021 02-May-2021 INDIA 10 30 UAE 20 80 USA 300 10 Whenever executing the script, a new column is added automatically with the current date. I require to convert this table data into HTM ...

Is it possible to reset only certain data values in Vue without re-initializing the entire set?

In the development process, we often encounter the need to re-initialize data structures. One common method is as follows: function initialData() { return { is_active: true, is_collapsed: true, resetable_data: 'value' ...

Utilize Javascript to convert centimeters into inches

Can anyone help me with a JavaScript function that accurately converts CM to IN? I've been using the code below: function toFeet(n) { var realFeet = ((n*0.393700) / 12); var feet = Math.floor(realFeet); var inches = Math.round(10*((realFeet ...

Requesting Axios.get for the value of years on end

I'm grappling with obtaining a JSON file from the server. The endpoint requires a year parameter, which needs to be set as the current year number as its value (e.g., ?year=2019). Furthermore, I need to fetch data for the previous and upcoming years a ...

Maintaining the initial value of a textbox in jQuery across various focusin events

Struggling to accurately explain the process, so feel free to check out this helpful fiddle. In my form, there are several text input fields and a single submit button. The submit button becomes enabled once any of the form fields have been altered. If a ...

Resize a group of images to match the parent's width and height dimensions

I am working with a div that contains variously-sized images and is nested inside a parent container. <div id="parentContainer"> <div id="boxToScale"> <img src="http://placehold.it/350x150" /> <img src="http://placehold.it/150 ...

Adjust the styling of selected elements when their values are changed

I am attempting to modify the background color based on the selected value that is returned. However, my current code doesn't seem to be working as expected: <script> $(document).ready(function() { $('#assessments').change(functi ...

Error message in TinyMCE stating that the right-hand side of the 'instanceof' operator is not callable

For over a year now, I have been utilizing TinyMCE on my website without any issues. However, today it has suddenly ceased functioning and is displaying the following error message. Can anyone provide guidance on resolving this issue? https://i.sstatic. ...

Eliminate jQuery's delayed blinking effect with the use of an event

Utilizing the mouseenter and mouseleave events, I have implemented a functionality to add a button (not actually a button) to an <li>. However, there seems to be a problem with my code. The button appears and disappears on mouseleave and mouseenter, ...

Navigation website with a twist

My design features a main navigation that is rotated 90 degrees, while the sub-menu remains horizontally aligned. <div id="nav"> <ul> <li><a href="#">Woonaccessoires</a></li> ...

Avoid Refreshing the Page When Pressing the Like Button

I've been working on code for liking a post and saving the value to a database using server-side code. However, I'm running into some issues when the page refreshes after clicking the like button. I tried using event.preventDefault() in my JavaSc ...

"Unfortunately, the Datatables Individual Column Search feature is not compatible with the

I am currently using Datatables to showcase a large dataset with over a thousand rows in a table format. To enable users to search for specific information within each column, I have implemented the feature of individual column search. The initial setup of ...

Is it possible for an HTML number input's arrows to change in increments that are different from its designated step attribute?

Within my design, I have implemented an <input type="number" step="1"> element for selecting font size. However, in the context of working on a large canvas, adjusting the number by 1 is hardly noticeable. It would greatly enhance ...

Crafting numerous CSS templates

I am currently working on creating multiple boxes or templates (5 on each row) from a movie API. I have successfully retrieved all the necessary data and do not require a responsive design. https://i.sstatic.net/CNz9R.png The issue arises when I attempt ...