html - Tabset 不显示选项卡内容

标签 html css tabs

如果按“tab Two”,它工作得很好。但是,如果您尝试按“Tab one”返回,它不会显示 tab one 内容。

我尝试了不同的方法,但我找不到我应该在代码中修改什么以使其工作。

HTML:

<div class="tabs">
    <div class="tab">
        <input type="radio" id="tab-1" name="tab-group-1" checked="">
        <label for="tab-1">
           Tab One
        </label>
        <div class="content">
            Content One
        </div>
    </div>
    <div class="tab">
        <input type="radio" id="tab-2" name="tab-group-2">
        <label for="tab-2">
            Tab Two
        </label>
        <div class="content">
            Content Two
        </div>
    </div>
</div>

CSS:

.tabs {
  position:relative;
  min-height:200px;
  clear:both;
  margin:25px 0;
  }
.tab {
  float:left;
  }
.tab label {
  background:#eee;
  padding:10px;
  border:1px solid #ccc;
  margin-left:-1px;
  position:relative;
  left:1px;
  top:1px;
  cursor:pointer;
  }
.tab label:hover {
  background:#f8f8f8;
  }
.tab [type=radio] {
  display:none;
  }
.content {
  background:white;
  position:absolute;
  top:28px;
  left:0;
  right:0;
  bottom:0;
  padding:20px;
  border:1px solid #ccc;
  }
[type=radio]:checked ~ label {
  background:white;
  border-bottom:1px solid white;
  z-index:2;
  }
[type=radio]:checked ~ label ~ .content {
  z-index:1;
  }

这是一个 fiddle :http://jsfiddle.net/36r0ptat/

最佳答案

尝试使用其他构造

<div class="tabs">
    <div class="tab" id="tab-1">
        <div class="content">Content One</div>
    </div>
    <div class="tab" id="tab-2">
        <div class="content">Content Two</div>
    </div>
    <ul class="tabs-link">
        <li class="tab-link"> <a href="#tab-1"><span>Tab 1</span></a>

        </li>
        <li class="tab-link"> <a href="#tab-2"><span>Tab 2</span></a>

        </li>
    </ul>
</div>

并修改了css

.tabs {
    position:relative;
    min-height:200px;
    clear:both;
    margin:25px 0;
}
.tab {
    float:left;
    display: none;
}
.tab:first-of-type {
    display: inline-block;
}
.tabs-link {
    position: relative;
    top: -12px;
    height: 20px;
    left: -40px;
}
.tab-link {
    background:#eee;
    display: inline-block;
    padding:10px;
    border:1px solid #ccc;
    margin-left:-1px;
    position:relative;
    list-style-type: none;
    left:1px;
    top:1px;
    cursor:pointer;
}
.tab-link {
    background:#f8f8f8;
}
.content {
    background:white;
    position:absolute;
    top:28px;
    left:0;
    right:0;
    bottom:0;
    padding:20px;
    border:1px solid #ccc;
}
.tab:target {
    display: block;
}

您可以修改自己需要的标签

fiddle :http://jsfiddle.net/Anglan/36r0ptat/4/

关于html - Tabset 不显示选项卡内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32718334/

相关文章:

html - 为什么在某些html页面中CSS部分被注释了?

html - css h1 字体大小与宽度一样大

javascript - 单击时在溢出 DIV 内滚动

html - 帖子注释滑过 Tumblr 永久链接页面中的帖子

netlify 网站上的 xaringan 幻灯片未调用 css 库

jQuery 切换问题 : animates twice

python - 将 XML 非法 &char 转换为 utf8 - python

jquery-validate - jquery滑动选项卡 "side effect"

javascript - 单击时使用选项卡在页面底部显示隐藏的内容

tabs - 带额外选项卡的 Silverstripe 模型管理