膠囊-邊框傾斜選擇器

2021-06-16_213358.png

這種導(dǎo)航網(wǎng)上很難找到資源,都是一堆亂七八糟的東西,完全不知道是啥玩意

下面的代碼是自個(gè)寫的,樣式可自己調(diào)整

代碼是完整代碼,復(fù)制粘貼就能使用

<template>
  <div class="CapsuleSelect_main-div">
    <ul class="ul_nav">
      <li
        v-for="(item, index) in options"
        :key="index"
        :class="index == activeIndex ? 'active' : ''"
        @click="change(item, index)"
      >
        <label>{{ item.label }}</label>
      </li>
    </ul>
  </div>
</template>
<script>
export default {
  name: "CapsuleSelect",
  props: {
    options: {
      type: Array,
      default: () => [
        {
          label: "標(biāo)簽",
          value: "0"
        },
        {
          label: "標(biāo)簽2",
          value: "2"
        }
      ]
    }
  },
  data() {
    return {
      activeIndex: 0 // 激活的標(biāo)簽下標(biāo)
    };
  },
  created() {},
  methods: {
    change(item, index) {
      this.activeIndex = index;
      this.$emit("sendMsg", item);
    }
  }
};
</script>
<style lang="scss" scoped>
$default: none; // 默認(rèn)背景色為空
$borderColor: #5b6299; // 邊框顏色
$activeColor: #5b6299; // 激活時(shí)的顏色
$fontColor: #9296ab; // 字體顏色
$fontSize: 14px; // 字體大小,默認(rèn)14px
$fontActive: #fff; // 激活時(shí)的字體顏色
$fontStrong: 400; // 字體粗細(xì)
.CapsuleSelect_main-div {
  .ul_nav li {
    display: inline-block;
    border: 1px solid $borderColor;
    padding: 6px 14px;
    transform: skew(35deg);
    border-left: 0;
    background: $default;
    label {
      display: inline-block;
      transform: skew(-35deg);
      font-size: $fontSize;
      color: $fontColor;
      font-weight: $fontStrong;
    }
    label:hover {
      cursor: pointer;
    }
  }

  .ul_nav li:first-of-type {
    padding-left: 7px;
    padding-right: 14px;
  }
  .ul_nav li:first-of-type::before {
    content: "";
    width: 50px;
    height: 29px;
    display: block;
    border-left: 1px solid $borderColor;
    border-top: 1px solid $borderColor;
    border-bottom: 1px solid $borderColor;
    position: absolute;
    transform: skew(-35deg);
    top: -1px;
    left: -20px;
    border-radius: 20px 0 0 20px;
  }
  .ul_nav li:last-of-type {
    border-right: 0;
    padding-left: 14px;
    padding-right: 7px;
  }
  .ul_nav li:last-of-type::before {
    content: "";
    width: 50px;
    height: 29px;
    display: block;
    position: absolute;
    transform: skew(-35deg);
    top: -1px;
    right: -20px;
    border-radius: 0 20px 20px 0;
    border-right: 1px solid $borderColor;
    border-top: 1px solid $borderColor;
    border-bottom: 1px solid $borderColor;
  }
  .ul_nav .active {
    background: $activeColor;
  }
  .ul_nav .active::before {
    content: "";
    background: $activeColor;
  }
  .ul_nav .active {
    label {
      color: $fontActive;
    }
  }
}
</style>

有些樣式冗余,懶得該。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容