动态设置后选择器的宽度

时间:2018-11-19 13:53:35

标签: jquery html css

我正在使用CSS创建一个类似于功能的简单标签。

当选项卡处于活动状态时,我使用tab-slider--tabs:after选择器设置所选选项卡的CSS。但是,Tab标头文本之一比另一个长,因此图像看起来像这样:

enter image description here

如何动态设置宽度,使其看起来像这样:

enter image description here

 .tab-slider--tabs {
  display: block;
  float: left;
  margin: 0;
  padding: 0;
  list-style: none;
  position: relative;
  border-radius: 35px;
  overflow: hidden;
  background: #fff;
  height: 35px;
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;
}
.tab-slider--tabs:after {
  content: "";
  width: 50%;
  background: #345F90;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  transition: all 250ms ease-in-out;
  border-radius: 35px;
}
.tab-slider--tabs.slide:after {
  left: 50%;
}

这里是:Demo Code

更新:我能够使用.tab-slider--trigger {width:30%;显示:表格单元格; ...}但我仍在寻找正确的方法。

1 个答案:

答案 0 :(得分:0)

尝试一下:

.tab-slider--trigger {
  width:150px;
  font-size: 12px;
  line-height: 1;
  font-weight: bold;
  color: #345F90;
  text-transform: uppercase;
  text-align: center;
  padding: 11px 20px;
  position: relative;
  z-index: 2;
  cursor: pointer;
  display: inline-block;
  transition: color 250ms ease-in-out;
  -webkit-user-select: none;
     -moz-user-select: none;
      -ms-user-select: none;
          user-select: none;
}
相关问题