【问题标题】:active tab text color change活动选项卡文本颜色更改
【发布时间】:2022-01-20 02:35:40
【问题描述】:

<div class="tabs-tending">
               <div class="tabs-tending-2">
                <label for="tabs-tending-1"class="ten-mhead">TRENDING <span>|<span></label>
                 <input id="tabs-tending-1" name="tabs-two" type="radio" checked="checked">
                   <div>
                 <p>content</p>
    </div>
  </div>
  <div class="tabs-tending-2">
    <label for="tabs-tending-2" class="fav-mhead">FAVOURITES</label>
    <input id="tabs-tending-2" name="tabs-two" type="radio">
    <div>
       <p>content</p>
    </div>
  </div>
</div>

我有一个带有内部选项卡内容的两个选项卡列表,切换时两个选项卡文本颜色相同,但我需要将活动选项卡文本颜色更改为黑色,非活动选项卡文本颜色将为灰色,我在 css 中尝试过但切换时看起来不一样,这里添加了html和css,请检查。提前致谢

.tabs-tending {
  display: block;
  display: -webkit-flex;
  display: -moz-flex;
  display: flex;
  -webkit-flex-wrap: wrap;
  -moz-flex-wrap: wrap;
  flex-wrap: wrap;
  margin: 0;
  overflow: hidden; }
  .tabs-tending [class^="tab"] label,
  .tabs-tending [class*=" tab"] label {
    color: #000000;
    cursor: pointer;
    display: block;
    font-size: 1.0em;
    font-weight: 600;
    line-height: 1em;
    padding: 0.5rem 0;
    text-align: center; }
  .tabs-tending [class*=" tab"] label {
    color: #000000;
    cursor: pointer;
    display: block;
    font-size: 1.0em;
    font-weight: 600;
    line-height: 1em;
    padding: 0.5rem 0;
    text-align: center; }
  .tabs-tending [class^="tab"] [type="radio"],
  .tabs-tending [class*=" tab"] [type="radio"] {
   /*  border-bottom: 1px solid rgba(239, 237, 239, 0.5); */
    cursor: pointer;
    -webkit-appearance: media-slider;
    -moz-appearance: media-slider;
    appearance: media-slider;
    display: block;
    width: 100%;
    -webkit-transition: all 0.3s ease-in-out;
    -moz-transition: all 0.3s ease-in-out;
    -o-transition: all 0.3s ease-in-out;
    transition: all 0.3s ease-in-out; }
    .tabs-tending [class^="tab"] [type="radio"]:hover, 
    .tabs-tending [class^="tab"] [type="radio"]:focus,
    .tabs-tending [class*=" tab"] [type="radio"]:hover,
    .tabs-tending [class*=" tab"] [type="radio"]:focus {
      /* border-bottom: 1px solid #ffc20e; */}
    .tabs-tending [class^="tab"] [type="radio"]:checked,
    .tabs-tending [class*=" tab"] [type="radio"]:checked {
      /* border-bottom: 2px solid #009297; */ }
    .tabs-tending [class^="tab"] [type="radio"]:checked + div,
    .tabs-tending [class*=" tab"] [type="radio"]:checked + div {
      opacity: 1; }
    .tabs-tending [class^="tab"] [type="radio"] + div,
    .tabs-tending [class*=" tab"] [type="radio"] + div {
      display: block;
      opacity: 0;
      padding: 0rem 0;
      width: 90%;
      -webkit-transition: all 0.3s ease-in-out;
      -moz-transition: all 0.3s ease-in-out;
      -o-transition: all 0.3s ease-in-out;
      transition: all 0.3s ease-in-out; }
  .tabs-tending .tabs-tending-2 {
    width: 50%; }
    .tabs-tending .tabs-tending-2 [type="radio"] + div {
      width: 200%;
      margin-left: 200%; }
    .tabs-tending .tabs-tending-2 [type="radio"]:checked + div {
      margin-left: 0; }
    .tabs-tending .tabs-tending-2:last-child [type="radio"] + div {
      margin-left: 100%; }
    .tabs-tending .tabs-tending-2:last-child [type="radio"]:checked + div {
      margin-left: -100%; }

【问题讨论】:

  • 找不到工作的 sn-p
  • 感谢您的回复,并给予您及时的答复,非常感谢!...这里是冗长的html代码,为什么我没有添加,请您检查css代码
  • 在标签上单击tab中的库添加的类
  • 这个类 .tabs-tending [class*=" tab"] label { color: #000000;光标:指针;显示:块;字体大小:1.0em;字体粗细:600;行高:1em;填充:0.5rem 0;文本对齐:居中;
  • 显示完整的标签页 html

标签: html css tabs


【解决方案1】:

我认为如果您将样式更改为类名,它应该可以工作。

  • 与元素一起使用时,for 属性指定标签绑定到哪个表单元素。

每个人:W3

这可以使用简单的 CSS 来完成。

.ten-mhead, .fav-mhead {
  color: lightgrey;
  padding: 5px;
  cursor: pointer;
}

.ten-mhead:active, .fav-mhead:active {
  color: black;
}
<label for="tabs-tending-1"class="ten-mhead">tab 1</label>
<label for="tabs-tending-2" class="fav-mhead">tab 2</label>

编辑:这是您要寻找的行为吗?

label {
  color: grey;
}

input[type="radio"]:checked + label {
  color: black;
}

input[type="radio"] {
  position: absolute;
  left: 6.5rem;
}

.tabs-tending {
  display: flex;
  flex-direction: column;
}
<div class="tabs-tending">
   <div class="tabs-tending-2">
      <input class="checked" name="tabs-two" type="radio">
      <label class="ten-mhead">TRENDING |</label>
      <div>
         <p>content</p>
      </div>
   </div>
   <div class="tabs-tending-2">
      <input class="checked" name="tabs-two" type="radio">
      <label class="fav-mhead">FAVORITES |</label>
      <div>
         <p>content</p>
      </div>
   </div>
</div>

【讨论】:

  • 感谢您的回复并给予您宝贵的时间,非常感谢!我需要一个选项卡功能,其中一个是黑色的,而不是悬停
  • @Designer16 查看编辑。这是你想要的?
【解决方案2】:

.tabs-tending {
  display: block;
  display: -webkit-flex;
  display: -moz-flex;
  display: flex;
  -webkit-flex-wrap: wrap;
  -moz-flex-wrap: wrap;
  flex-wrap: wrap;
  margin: 0;
  overflow: hidden; }
  .tabs-tending [class^="tab"] label,
  .tabs-tending [class*=" tab"] label {
    color: #000000;
    cursor: pointer;
    display: block;
    font-size: 1.0em;
    font-weight: 600;
    line-height: 1em;
    padding: 0.5rem 0;
    text-align: center; }
  .tabs-tending [class*=" tab"] label {
    color: #000000;
    cursor: pointer;
    display: block;
    font-size: 1.0em;
    font-weight: 600;
    line-height: 1em;
    padding: 0.5rem 0;
    text-align: center; }
  .tabs-tending [class^="tab"] [type="radio"],
  .tabs-tending [class*=" tab"] [type="radio"] {
   /*  border-bottom: 1px solid rgba(239, 237, 239, 0.5); */
    cursor: pointer;
    -webkit-appearance: media-slider;
    -moz-appearance: media-slider;
    appearance: media-slider;
    display: block;
    width: 100%;
    -webkit-transition: all 0.3s ease-in-out;
    -moz-transition: all 0.3s ease-in-out;
    -o-transition: all 0.3s ease-in-out;
    transition: all 0.3s ease-in-out; }
    .tabs-tending [class^="tab"] [type="radio"]:hover, 
    .tabs-tending [class^="tab"] [type="radio"]:focus,
    .tabs-tending [class*=" tab"] [type="radio"]:hover,
    .tabs-tending [class*=" tab"] [type="radio"]:focus {
      /* border-bottom: 1px solid #ffc20e; */}
    .tabs-tending [class^="tab"] [type="radio"]:checked,
    .tabs-tending [class*=" tab"] [type="radio"]:checked {
      /* border-bottom: 2px solid #009297; */ }
    .tabs-tending [class^="tab"] [type="radio"]:checked + div,
    .tabs-tending [class*=" tab"] [type="radio"]:checked + div {
      opacity: 1; }
    .tabs-tending [class^="tab"] [type="radio"] + div,
    .tabs-tending [class*=" tab"] [type="radio"] + div {
      display: block;
      opacity: 0;
      padding: 0rem 0;
      width: 90%;
      -webkit-transition: all 0.3s ease-in-out;
      -moz-transition: all 0.3s ease-in-out;
      -o-transition: all 0.3s ease-in-out;
      transition: all 0.3s ease-in-out; }
  .tabs-tending .tabs-tending-2 {
    width: 50%; }
    .tabs-tending .tabs-tending-2 [type="radio"] + div {
      width: 200%;
      margin-left: 200%; }
    .tabs-tending .tabs-tending-2 [type="radio"]:checked + div {
      margin-left: 0; }
    .tabs-tending .tabs-tending-2:last-child [type="radio"] + div {
      margin-left: 100%; }
    .tabs-tending .tabs-tending-2:last-child [type="radio"]:checked + div {
      margin-left: -100%; }
      
      .tabs-tending [class^="tab"] [type="radio"]:checked ~ label,
    .tabs-tending [class*=" tab"] [type="radio"]:checked ~ label {
      color: red }
<div class="tabs-tending">
               <div class="tabs-tending-2">
                 <input id="tabs-tending-1" name="tabs-two" type="radio" checked="checked">
                 <label for="tabs-tending-1"class="ten-mhead">TRENDING <span>|<span></label>
                   <div>
                 <p>content</p>
    </div>
  </div>
  <div class="tabs-tending-2">
    <input id="tabs-tending-2" name="tabs-two" type="radio">
    <label for="tabs-tending-2" class="fav-mhead">FAVOURITES</label>
    <div>
       <p>content</p>
    </div>
  </div>
</div>

【讨论】:

  • 感谢您的宝贵时间,此代码后应用选项卡功能不起作用
猜你喜欢
  • 2018-03-26
  • 1970-01-01
  • 2016-07-26
  • 1970-01-01
  • 1970-01-01
  • 2016-04-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多