<分区>
我正在尝试使用 this recepee在不使用 JS 或 JQuery、纯 CSS 的情况下实现选项卡,但我被卡住了。 目标是在点击某个标签时显示不同的内容,并更改标签样式。 现在它显示了我想要的标签,但每个 div 的内容以某种方式显示在标签上方,而不是标签下方。另外,我不能让它改变风格。有人可以帮忙吗?谢谢。对不起,如果这个问题看起来很愚蠢 - 我只是从 html 开始。
<div id="menu">
<label class="collapse" for="1">tab1</label> <input id="1" name="r" type="radio" />
<div>111111111111111111111</div>
<label class="collapse" for="2">tab2</label> <input id="2" name="r" type="radio"/>
<div>2222222222222222222222</div>
<label class="collapse" for="3">tab3</label> <input id="3" name="r" type="radio" />
<div>333333333333333333333</div>
</div>
我的CSS:
#menu {
padding-left: 20px;
}
#menu label {
height: 30px;
background-color: #d1ecee;
width: 75px;
color: #2cb674;
font-size: 12px;
line-height: 30px;
text-align: center;
float: left;
position: relative;
margin-left: 2px;
display:block;
margin-right: 20px;
}
#menu label:before {
content: "";
position: absolute;
left: -20px;
width: 0;
height: 0;
border-top: 30px solid #d1ecee;
border-left: 20px solid transparent;
display:block;
}
#menu label:after {
content: "";
position: absolute;
right: -20px;
width: 0;
height: 0;
border-bottom: 30px solid #d1ecee;
border-right: 20px solid transparent;
}
#menu input {
display: none !important;
}
#menu input+* {
display: none !important;
}
#menu input:checked+* {
display: block !important;
}
#menu input:checked+label {
background-color: #2cb674;
color: white;
}
#menu input:checked+label:before {
border-top: 30px solid #2cb674;
}
#menu input:checked+label:after {
border-bottom: 30px solid #2cb674;
}
更新: