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>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容