html标签选项卡,html – 仅限css3选项卡预选标签

这篇博客介绍了如何利用HTML的单选按钮和CSS创建一个选项卡式布局,其中内容区域通过z-index进行层级控制,实现切换时不进行页面跳转。CSS样式用于控制选项卡的显示和隐藏,以及选中状态下的样式变化。
摘要由CSDN通过智能技术生成

您可以使用单选按钮和:checked class来创建它.

它不使用:target,因此不会有任何页面跳转.

正如您在下面的代码示例中所看到的,每个选项卡都包含单选按钮(用于功能),其中隐藏了display:none,标签作为选项卡和内容div.

HTML

Tab 1

This content appears on tab 1.

Tab 2

This content appears on tab 2.

Tab 3

This content appears on tab 3.

内容区域以绝对定位位于彼此之上,当选中单选按钮时,使内容区域位于z-index的顶部.

CSS

.tabs {

position: relative;

min-height: 200px; /* This part sucks */

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;

}

.tab [type=radio] {

display: none;

}

.content {

position: absolute;

top: 28px;

left: 0;

background: white;

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;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值