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

A guide on creating a clickable polygon in Vue.js using Konva

Is there a way to create an interactive polygon in Vue Konva where I can set each corner with a click? I haven't been able to find any resources other than the v-polygon which only creates predefined polygons. ...

What is the best way to prevent users from entering a zero in the first position of a text box using JavaScript

Although I am aware this may be a duplicate issue, the existing solution does not seem to work for me. The field should accept values like: valid - 123,33.00, 100,897,99, 8000 10334 9800,564,88.36 invalid - 001, 0 ...

Learn the steps to successfully rotate the custom icon in Material-Ui select without impacting its functionality and making sure it remains clickable

I've been trying to incorporate my own icon for the material UI select component. I successfully replaced the default icon using the "IconComponent" attribute in MU select. However, I'm facing issues with the new icon not rotating when the menu ...

Incorporate input-style labeling into Vuetify's v-card component

https://i.stack.imgur.com/CMs0l.png Is there a way to add a label similar to a v-input's label to a v-card, just like in the example of "select" above? If so, how can this be achieved? I was considering appending a label using code, but I believe t ...

The URL routing in Vue-router seems to be incorrect as it directs to the wrong page. To fix this issue, make sure to include a '#' before the

Welcome to my website! Check out my home page here: https://i.sstatic.net/znfq0.jpg If you're interested in reading my blog, visit the blog page here: https://i.sstatic.net/oiYSY.png I've built this site using vue3. Here's a snippet of th ...

When using BeautifulSoup, there may be instances where the table element is not always detected, resulting in a 'NoneType' error being returned on occasion

Hello everyone, I am trying to retrieve accurate daily temperatures from www.wunderground.com and encountering the 'NoneType' error occasionally. For instance, the code below attempts to fetch the temperature data from March 1 to March 5, 2020. S ...

Adjust the height of a division dynamically

I have the following HTML snippet: <div id="container"> <div id="feedbackBox"></div> </div> The #feedbackBox div is initially not visible. To center the div, the CSS code is used: #container { position: absolute; widt ...

Utilizing a window.onload function in Microsoft Edge

After trying to run some code post-loading and rendering on the target page, I was recommended to use the Window.load function. This method worked flawlessly in Firefox and Chrome, but unfortunately, I couldn't get it to function in IE. Is there an al ...

VueJS: Preloading data prior to and following component initialization

VueJS is a new technology for me, and I'm currently working on a component that needs to retrieve data from an API before loading the corresponding route. The component should only load once the data is fetched. Additionally, after the component is cr ...

Transform the post data into a JSON string within the controller

Hello everyone, I have a sample table that I want to share: <table class="table table-bordered" width="100%" cellspacing="0" id="tableID"> <thead> <tr> <th>A</th> <th>B</th> <th>C< ...

Using Swagger with Next.js

Is it possible to generate Swagger documentation for API routes in NEXT.js? I am working with Next.js for both front-end and back-end tasks, and I am interested in creating a Swagger documentation for the APIs implemented in Next.js. ...

Creating a scrollable nested div on a mobile website

Is there a way to achieve a scrollable nested div on a jQuery mobile site? I am aiming for a fixed header and footer with the middle section being scrollable. Despite my attempts to set overflow:scroll (along with specifying the width and height of the div ...

Leveraging Async/Await to track error counts across three distinct loops, each invoking an asynchronous function in every iteration

While I have experience with Callbacks, Async/Await and Promises are new concepts to me. In my node.JS server project, I am faced with the challenge of counting errors generated by thousands of asynchronous calls from three different async functions. My g ...

What is the best way to reference an ImageButton using jquery?

I created an HTML page with a special div in the body that contains a collection of buttons and images. <div id="div_one"> <button id="button_one"> <asp:Image id="image_button_one" ImageUrl=".." runat="server"> </button> </div& ...

Converting Scalable Vector Graphics to Hypertext Markup Language and

So I've got this SVG file called 7.svg. What's the best way to show this image using HTML or CSS on my index.html page? ...

What steps should be taken to avoid an event from occurring when an error message is encountered?

I have a dropdown list of cars where an error message is displayed if any of them becomes inactive. When the error message is shown, clicking on the Route Car button should prevent any event from occurring, i.e., no modal popup should be displayed. How ca ...

What is the best way to remove all elements in jQuery?

I need to remove the selected element in my demo using jstree. I have consulted the plugin's API at http://www.jstree.com/api/#/?f=deselect_all([supress_event]), but it seems that it does not deselect the item properly. Here are the steps I have follo ...

Display extensive text content in HTML for mobile devices

As I work on developing a web app, specific requirements must be met: Pages that can dynamically load large amounts of text (around 30-100 printed pages) in HTML using $.ajax based on complex functions The complete text must be loaded upfront and cannot ...

JavaScript and CSS animations offer dynamic and engaging ways to bring

I'm working on a div section and I want it to come down and rotate when a button is clicked. However, after moving to the bottom, it doesn't rotate as expected but instead returns to its initial position along the Y axis. How can I fix this issue ...

What could be causing the misalignment of the Datepicker calendar in Material UI?

I have integrated a datepicker using the library "@mui/x-date-pickers/DatePicker". import { DatePicker } from "@mui/x-date-pickers/DatePicker"; import { AdapterMoment } from "@mui/x-date-pickers/AdapterMoment"; import { Locali ...