Arranging cards in a stack using VueJS

I am currently working with a small vue snippet. Originally, I had v-for and v-if conditions in the snippet, but due to issues reading the array, it is now hardcoded.

The current setup produces three cards stacked on top of each other. I am exploring options within Vue to have these cards displayed like a deck, where only about 20% of the top of each card is visible, and clicking on a card expands it (similar to an accordion).

I have attempted setting negative margins at the bottom, but it does not seem to have the desired effect. Is there a more effective way to approach this layout in Vue?

export default{
         data() {
           return { 
             copiedUsers:[
               {copied_user_email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="97e3f2e4e3e2e4f2e5d7faf6fefbb9f4f8fa">[email protected]</a>"},
               {copied_user_email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ed99889e99989e889fdfad808c8481c38e8280">[email protected]</a>"},
               {copied_user_email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9beffee8efeee8fee9a8dbf6faf2f7b5f8f4f6">[email protected]</a>"}
             ]
           }
         }
       }
.card {
           position: relative;
           display: flex;
           flex-direction: column;
           min-width: 0;
           word-wrap: break-word;
           background-color: #fff;
           background-clip: border-box;
           border: 1px solid #dee2e6;
           border-radius: 0.5rem;
           margin-bottom:-80px;
           }
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f6808393b6c4d8c0d8c7c7">[email protected]</a>/dist/vue.js"></script>

       <div id='app'>
        <div v-for="(copy, idx) in copiedUsers" :key="idx">
          <div 
         class="card" 
         :style="{ 
           top: idx * 10 + 'px', // <-- dynamic top
           left: idx * 6 + 'px' // <-- dynamic left
         }">
        </div>
      </div>
     </div>

Answer №1

If you want to add a specific range based on the indices, one way to achieve this is by using style-binding with :style.

Here's an example to help illustrate the concept:

new Vue({
  el: '#app',
  data: {
  copiedUsers:[
    {copied_user_email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1b6f7e686f6e687e695b767a727735787476">[email protected]</a>"},
    {copied_user_email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4e3a2b3d3a3b3d2b3c7c0e232f2722602d2123">[email protected]</a>"},
    {copied_user_email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f98d9c8a8d8c8a9c8bcab994989095d79a9694">[email protected]</a>"}
   ]
  }
})
.card {
 position: absolute;
 width: 40px;
 height: 65px;
 background-color: #777;
 border: 1px solid #333;
}
<script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7503001035475b435b4444">[email protected]</a>/dist/vue.js"></script>

<div id='app'>
 <div v-for="(copy, idx) in copiedUsers" :key="copy.id">
   <div 
     class="card" 
     :style="{ 
       top: idx * 10 + 'px', // <-- dynamic top
       left: idx * 6 + 'px' // <-- dynamic left
    }">
   </div>
 </div>
</div>

You can also use dynamic margins or paddings by creating a computed property to keep your template clean and easy to understand.

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

An unexpected error occurred while attempting to retrieve data from Firebase and display it in another component

An error occurred: Unhandled Runtime Error Error: Element type is invalid - expected a string (for built-in components) or a class/function (for composite components) but got undefined. This could be due to forgetting to export your component from the defi ...

What is the best way to ensure DIVs or SPANs have a fixed width with their content while also utilizing the remaining available space with white space?

My current setup is similar to the following. <div width="100%"> <span width="33%">FIRSTNAME</span> <span width="33%">|LASTNAME</span> <span width="33%">|CITY</span> </div> When executed, it appears a ...

What steps can I take to resolve this issue when encountering an error during npm install?

As a newcomer to programming, I am embarking on the creation of a Discord bot using node and discord.js. My current hurdle involves the installation of a library named canvas, which seems to be causing issues. After developing and testing my application o ...

The beforePopState event in next/router is not triggering as expected

Noticing an issue where the beforePopState event is not triggering when I use the back button. This code snippet is part of a hook defined in _app.js according to the documentation. The current version being used is 12.1.5 If anyone has insights on what ...

Assign the array value to all inputs that share the same class tag

Does anyone know how to iterate through all tags with the same className and retrieve their values? var quantities = []; $(".add_more_items").each(function(){ quantities.push($(this).val()); }); Here is an example of the result: ['1&apo ...

Releasing the mouse button after dragging successfully without the use of any libraries

I have implemented a pure CSS snap scroll feature and now I need to determine the position of an element in relation to the viewport once the user stops dragging. However, I prefer not to rely on any complex libraries as I do not require any actual movemen ...

Explore the possibility of utilizing Excel VBA to locate images from websites and seamlessly import them into

Right now, my main goal is to browse an open webpage in search of multiple png images and then import them into various cells within a tab on my Excel workbook. The current macro I have takes me through the webpage where I can see which pictures are displ ...

A guide on combining two native Record types in TypeScript

Is it possible to combine two predefined Record types in TypeScript? Consider the two Records below: var dictionary1 : Record<string, string []> ={ 'fruits' : ['apple','banana', 'cherry'], 'vegeta ...

Setting up a Contact Email for your Nuxt Static Generated site: A Step-by-Step Guide

I have a website built on Nuxt and hosted on Netlify. I utilized the 'static' method in my nuxt.config.js file to generate the dist folder. My goal is to trigger an email notification whenever a user submits a contact form on my site. It functio ...

iOS Safari: Full-width header with fixed position exceeding viewport width

Encountered an issue specific to Safari on iOS. Creating a page with a fixed position header that spans the width of the viewport. The content consists of multiple images that should scroll horizontally while the header remains in place during scrolling. ...

What method can be used to keep Chromium open while using Puppeteer?

I am trying to figure out how to launch only one instance of Chromium from my first script and then connect to it from subsequent scripts. I am aware of the puppeteer.connect() method, but the issue is that when I start the script responsible for launching ...

Parent's hover element

I am currently working with the following loop: <?php if( have_rows('modules') ): $counter = 0; while ( have_rows('modules') ) : the_row(); ?> <div class="col span_4_of_12 <?php if($counter == 0) { ?>firs ...

How can I globally expose my APIService.js class to Vue JS components without needing to import it in each individual component?

Most of my components rely on interactions with my apiservice.js class, which uses Axios to handle http requests based on the method called. I understand that this may not be the recommended approach, but in every component, I include the following code: ...

Embedding Vue component into a traditional PHP/jQuery project

Currently, I have a large legacy web application that is primarily built using Codeigniter and jQuery. Our strategy moving forward involves gradually transitioning away from jQuery and incorporating Vuejs into the project instead. This process will involv ...

What is the best way to bring up the keyboard on an iPhone when focusing an HTML text field?

Currently working on developing a web app for iPhone, and looking to implement a feature where a text field is automatically focused upon page load, prompting the keyboard to appear. Despite attempting the standard Javascript method: input.focus(); I see ...

Constructing an Http Post URL with form parameters using the Axios HTTP client

I need assistance in creating a postHTTP request with form parameters using axios on my node server. I have successfully implemented the Java code for constructing a URL, as shown below: JAVA CODE: HttpPost post = new HttpPost(UriBuilder.fromUri (getPro ...

Rendering dynamic HTML content using EJS

I've created a blog application using Express and MongoDB, with EJS for rendering the data. My issue lies in the styling of the content to resemble a paragraph: <div class="show-post__content"> <%= post.body %> </div> The po ...

Utilizing JSON API filtering within a Next.js application

Recently delving into the world of coding, I've embarked on a personal project that has presented me with a bit of a challenge regarding API filtering. My goal is to render data only if it contains a specific word, like "known_for_department==Directin ...

"Enhance Your Communication: Utilize setTimeout in Ajax

Hey there, I could really use some help with the setTimeout function in my code. No matter what I try, it just doesn't seem to work. I'm currently working on a chat system where I need to send and receive messages (testing by opening 2 browser ...

innovative jquery table creator

I have created a basic dynamic HTML table generator using jQuery, see below... <button id="addcolumn">Add Column</button> <button id="addrow">Add Row</button> <table width="100%" border="1" cellpadding="0" cellspacing="0"> ...