【发布时间】:2017-09-05 22:32:06
【问题描述】:
我想知道是否有办法在不使用 JavaScript 的情况下创建滚动标签。我被分配了一项严格使用 HTML 和 CSS 的任务,仅此而已。下面的代码是我能找到的最好的解决方案,它可以在不使用 HTML 和 CSS 之外的任何其他东西的情况下创建选项卡。我找到了一些用于在线滚动标签的代码,但它再次使用 JavaScript。那么,是否可以仅使用 HTML 和 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;
cursor:pointer;
position: relative;
left: 1px; }
.tab [type=radio]
{display: none;}
.content {position: absolute;
top: 28px;
left: 0;
background: white;
height:100px;
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;}
<div class="tabs">
<div class="tab">
<input name="tab-group-1" id="tab-1" type="radio"/>
<label for="tab-1">Tab One</label>
<div class="content">
Content 1
</div>
</div>
<div class="tab">
<input name="tab-group-1" id="tab-2" type="radio"/>
<label for="tab-2">Tab Two</label>
<div class="content"> Content 2 </div>
</div>
</div>
【问题讨论】: