html - 为每个图像应用固定的 px 单位

标签 html css vue.js

我有一张卡片图像,我需要重复它 30 次,每次我想申请一张特定卡片的左侧位置时,它会与卡片重叠,然后再停留在一副牌的位置上。

问题是,当我将左侧位置应用于图像卡片时,它会将相同的左侧位置应用于所有卡片,因此没有重叠位置。

所以我有这样的东西:

<template>
  <div class="triPack">
    <img :style="{'left': -index * 30}" v-for="index in 30" :key="index" src="../../assets/images/cardThemes/blue.png" alt="">
  </div>
</template>

<script>
export default {
}
</script>

<style lang="scss">
  .triPack {
    display: flex;
    img {
      width: 80px;
      height: 100px;
      position: relative;
    }
  }
</style>

enter image description here

我想要这样的东西:

enter image description here

谢谢你们。

最佳答案

除了第一张图片 :not(:first-child)

你可以只用 css margin-left 来做到这一点

所以删除它 :style="{'left': -index * 30}"

.triPack {
   display: flex;  }
img {
   width: 80px;
   height: 100px;
    position: relative;
    }
img:not(:first-child) {
margin-left: -45px;
}
 <div class="triPack">
    <img  src="/image/XG0gL.png" alt="">
    <img  src="/image/XG0gL.png" alt="">
    <img  src="/image/XG0gL.png" alt="">
    <img  src="/image/XG0gL.png" alt="">
    
  </div>

关于html - 为每个图像应用固定的 px 单位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51943954/

相关文章:

Vue.js 从 webpack 包中排除文件夹

vue.js - ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/components/table.vue 中的错误

javascript - window.location.hash 的编码

javascript - 如何获取所有具有固定起始字符串的html元素

javascript - 在 Ace 编辑器中禁用水平分割

css - 仅使用 CSS 居中内容?

html - 如何填补倾斜形状div和其他平面矩形div之间的差距

javascript - HTML - 如何滚动整个部分而不在中间停止?

javascript - 如何在响应式 UI 中固定 div 的位置

javascript - 如何在 O(1) 中更新 redux/vuex 存储中的元素?