如何使用css将单选按钮组堆叠在一起
How to stack radio button group on top of each other using css?
这是jsfiddle链接,现在它显示为
label1 a b c d e f
label2 a b c d e f
我想把职位改成
label1 a b c
d e f
label2 a b c
d e f
起初,我认为将它封装在div中是可行的,但事实并非如此。
<div ng-app>
<h2>Todo</h2>
<div ng-controller="TodoCtrl">
<div ng-repeat="k in test">
<input type="radio" name="what" value="k" >
<div style="display: inline-block;">
label {{k}}
</div>
<!-- getting rid of this inline-block here will cause the first group not align in the same horizontal line -->
<div ng-repeat="t in test2" style="display: inline-block;">
<div>
<div ng-repeat="n in t" style="display: inline-block;">
<input type="radio" name="what2" value="n" >
<div style="display: inline-block;">
{{n}}
</div>
</div>
</div>
</div>
</div>
有办法解决这个问题吗?
好吧,所以你需要在你的第一个ng重复div上设置一个宽度,然后我添加了一个名为"test"的类,并抓住了:nth child(4)(这是第二组单选按钮)。JSFiddle:http://jsfiddle.net/14wdtpem/代码如下:
<div ng-app>
<h2>Todo</h2>
<div ng-controller="TodoCtrl">
<div class="test" ng-repeat="k in test" style="width:200px">
<input type="radio" name="what" value="k" >
<div style="display: inline-block;">
label {{k}}
</div>
<div ng-repeat="t in test2" style="display: inline-block; ">
<div >
<div ng-repeat="n in t" style="display: inline-block; ">
<input type="radio" name="what2" value="n" >
<div style="display: inline-block;">
{{n}}
</div>
</div>
</div>
</div>
</div>
CSS:
.test :nth-child(4){
margin-left:65px;
}
为了解决这个问题,创建一个额外的div是不够的——我为字母单选按钮创建了一个inline-block
容器,然后为新的firstRow
和secondRow
分别创建了block
容器。这样,整个rows
容器可以显示在每个标签旁边。
希望这能有所帮助!
<div ng-app>
<h2>Todo</h2>
<div ng-controller="TodoCtrl">
<div ng-repeat="k in test">
<input type="radio" name="what" value="k">
<div style="display: inline-block">
label {{k}}
</div>
<div id="rows" style="display: inline-block">
<div id="firstRow" style="display: block;">
<div ng-repeat="t in test2[0]" style="display: inline-block;">
<div>
<div ng-repeat="n in t" style="display: inline-block;">
<input type="radio" name="what2" value="n">
<div style="display: inline-block;">
{{n}}
</div>
</div>
</div>
</div>
</div>
<div id="secondRow" style="display: inline-block">
<div ng-repeat="t in test2[1]" style="display: inline-block;">
<div>
<div ng-repeat="n in t" style="display: inline-block;">
<input type="radio" name="what2" value="n">
<div style="display: inline-block;">
{{n}}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
更新的小提琴。
相关文章:
- 需要在选择单选按钮上启用提交按钮
- 我需要在选择单选按钮时显示一个下拉框
- 如何在选择单选按钮后启用提交按钮
- 在动态单选按钮中只选择一个
- 如何在选中单选按钮(输入)时触发事件
- 如何在选中单选按钮时动态添加下拉元素
- 如何在选择单选按钮时更改隐藏表单数据的值
- 获取表单域以在选择单选按钮时清除
- 是否可以在更改单选按钮时禁用/启用jquery功能
- 如果语句不能在 Javascript 单选按钮上正常工作
- 防止在禁用单选按钮列表上调用 javascript 函数
- 如何在选择单选按钮时清除文本字段中的文本
- 在选择单选按钮时绘制窗体
- 动态弹出菜单,在选择单选按钮时将类添加到父级(如 Trello 的)
- 如何在选择单选按钮上显示文本字段
- 如何在一个单选按钮中显示传递给ajax的php值
- 在更改单选按钮时重新加载页面
- 如何在更改单选按钮上设置值
- Rails:在form_for单选按钮上调用JS函数
- 在选择单选按钮后,如何根据所选的单选按钮显示输出