css 巧用 ::after 和 ::before 实现竖排分类导航

2023-12-15 17:41:11

在这里插入图片描述

<template>
  <div class="container">
    <div class="primary">
      <div
        class="item"
        v-for="(item, index) in categoryList"
        :key="item.id"
        :class="{ active: index === activeIndex }"
        @click="activeIndex = index"
      >
        {{ item.label }}
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      activeIndex: 0,
      categoryList: [
        {
          label: "精选好物",
        },
        {
          label: "炫酷动漫",
        },
        {
          label: "贺岁影院",
        },
      ],
    };
  },
};
</script>

<style lang="scss" scoped>
.primary {
  overflow: hidden;
  width: 180px;
  flex: none;
  background-color: #f6f6f6;
  .item {
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 96px;
    font-size: 26px;
    color: #595c63;
    position: relative;
    &::after {
      content: "";
      position: absolute;
      left: 42px;
      bottom: 0;
      width: 96px;
      border-top: 1px solid #e3e4e7;
    }
  }
  .active {
    background-color: #fff;
    &::before {
      content: "";
      position: absolute;
      left: 0;
      top: 0;
      width: 8px;
      height: 100%;
      background-color: #27ba9b;
    }
  }
}

// 移除最后一项和高亮项的灰色线条
.primary .item:last-child::after,
.primary .active::after {
  display: none;
}
.container {
  margin: 30px;
}
</style>

文章来源:https://blog.csdn.net/weixin_41192489/article/details/134885007
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。