vue v-for展示元素分两栏 中间使用分割线

1.效果展示:

2.代码展示:

复制代码
<template>
  <div class="container">
    <div class="column" v-for="(item, index) in items" :key="index">
      <div class="item">{{ item }}</div>
      <div v-if="index % 2 !== 0" class="divider"></div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      items: ['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5']
    };
  }
};
</script>

<style scoped>
.container {
  display: flex;
  flex-wrap: wrap;

}

.column {
  flex: 0 0 50%; /* 每个元素占据50%的宽度 */
  max-width: 50%;
  padding: 10px;
  box-sizing: border-box;
  position: relative;
}

.item {
  background-color: #f0f0f0;
  padding: 20px;
  margin-bottom: 10px;
}

.divider {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px; /* 分割线的宽度 */
  background-color: #ccc; /* 分割线的颜色 */
  margin-left: -10px;
}
</style>
相关推荐
文滨4 分钟前
10分钟搞定!Mac 配置 GitHub SSH 完全指南(小白也能看懂)
前端·macos·ssh·github
时寒的笔记7 分钟前
11期_js逆向核心案例解析(sichuan&某理财网)
开发语言·javascript·ecmascript
2601_958492558 分钟前
7 WordPress Tools I Trust for Building a High-Traffic Magazine Site
前端·word
IT_陈寒19 分钟前
Java的finally块竟然不是你想的那个finally!
前端·人工智能·后端
_xaboy19 分钟前
开源Vue组件FormCreate通过 JSON 生成AntdvNext表单
vue.js·开源·json
2501_9400417421 分钟前
挖掘前端交互潜力的五款创意游戏原型
前端·游戏
C+-C资深大佬21 分钟前
变量作用域(通俗 + 清晰讲解,适合编程入门)
前端·javascript·vue.js
weelinking25 分钟前
【claude】15_Claude使用经验与最佳实践
前端·人工智能·python·sql·数据挖掘·前端框架·github
XS03010633 分钟前
HTML 入门教程
前端·html