vue類綁定配合css實現html5 tab

效果如圖:


微信截圖_20221202171042.png
微信截圖_20221202171107.png

代碼如下:

<template>
  <div class="relation-content">
    <div class="tabs">
      <div
        class="tab-item-box"
        :class="{
          'tab-item-active': currentTab !== index,
          'tab-item-noactive': currentTab === index
        }"
        v-for="(item, index) in tabs"
        :key="index"
        @click="currentTab = index"
      >
        <div
          class="tab-item"
          :class="{
            'tab-item-active': currentTab === index,
            'tab-item-noactive': currentTab !== index,
            'current-left': currentTab - index === 1,
            'current-right': index - currentTab === 1
          }"
        >{{item}}</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'relationContent',
  data() {
    return {
      tabs: ['視頻解讀', '圖文解說', '政策依據', '工單案例'],
      currentTab: 0
    }
  }
}
</script>

<style scoped>
.relation-content {
  position: relative;
  top: 12px;
  width: 85%;
  min-height: 100px;
  margin: 12px 0;
  border-radius: 12px;
  overflow: auto;
  box-shadow: 0px 0px 10px -1px #C2DAFF;
}
.tabs {
  width: 100%;
  overflow-x: auto;
}
.tabs .tab-item-box {
  float: left;
  width: 25%;
}
.tabs .tab-item {
  float: left;
  width: 100%;
  height: 36px;
  line-height: 36px;
  text-align: center;
  color: #333;
}
.tabs .tab-item-active {
  background-color: #fff;
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
}
.tabs .tab-item-noactive {
  background-color: #C2DAFF;
}
.tabs .current-left {
  border-color: #fff;
  border-bottom-right-radius: 18px;
}
.tabs .current-right {
  border-bottom-left-radius: 18px;
}
</style>
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容