【发布时间】:2017-09-04 14:05:43
【问题描述】:
上下文:我正在尝试使用 radio hack 来切换在 .tabinfo div 中查看的文本,但我的收音机和 display 的文本我要更改的属性位于不同的 div 中。
问题:是否可以使用纯 CSS 选择器通过单击嵌套单选来选择 #text 元素?
参考代码:我正在使用引导布局并创建了以下 HTML 代码:
<div class="col-xs-2">
<input id="tab1" type="radio" name="tabs">
<label for="tab1">Foo</label>
</div>
<div class="col-xs-2">
<input id="tab2" type="radio" name="tabs">
<label for="tab2">Bar</label>
</div>
<div class="col-xs-2">
<input id="tab3" type="radio" name="tabs" checked>
<label for="tab3">Foo Bar</label>
</div>
<div class="col-xs-12">
<div class="tabinfo">
<div id="text1">
</div>
<div id="text2">
</div>
<div id="text3">
</div>
</div>
</div>
还有以下 CSS:
label {
border: solid;
border-top-right-radius: 10px;
border-top-left-radius: 10px;
border-bottom: none;
border-color: rgb(211,211,205);
border-width: 2px;
color: rgb(12,174,175);
background-color: rgb(247,247,247);
}
input:checked + label {
background-color: #fff;
color: rgb(94,94,94);
}
label:hover {
cursor: pointer;
}
.tabinfo {
border: solid;
border-color: rgb(211,211,205);
border-width: 2px;
border-top-right-radius: 10px;
}
#tab1:checked ~ .col-xs-12 .tabinfo #text1,
#tab2:checked ~ .col-xs-12 .tabinfo #text2,
#tab3:checked ~ .col-xs-12 .tabinfo #text3 {
display: block!important;
}
正如您可能已经猜到的那样,由于#texts 和#tabs 位于不同的 div 中,因此上述方法不起作用。在不破坏 Bootstrap 布局的情况下,是否有任何解决方法或解决方案?
提前致谢。
【问题讨论】:
-
每个无线电输入应该影响哪些特定的“文本”? HTML可以改变吗?而且,顺便说一句,共享一个公共
name属性的组中只有一个无线电输入可以是checked。 -
抱歉造成误会,我刚刚写了上面的代码。每个带编号的选项卡都应影响数字文本,即如果选中#tab1,则显示#text1 等。人。只要不破坏引导布局,就可以更改 HTML。
标签: css twitter-bootstrap css-selectors radio-button css-hack