我正在添加文本框并动态选择元素,一个占用容器标签的整个宽度后添加到第二行。但我不想要第二行,如果容器的宽度不足以容纳所有标签,我应该得到一个水平滚动条
<div class="addContainer">
<label class="select ">
<select class="form-control" name="selecname" placeholder="" id="id1">
<option value="1">Pass</option>
<option value="0">Fail</option>
</select><i></i>
</label>
<label class="select ">
<select class="form-control" name="selecname" placeholder="" id="id1">
<option value="1">Pass</option>
<option value="0">Fail</option>
</select><i></i>
</label>
<label class="select ">
<select class="form-control" name="selecname" placeholder="" id="id1">
<option value="1">Pass</option>
<option value="0">Fail</option>
</select><i></i>
</label>
<label class="select ">
<select class="form-control" name="selecname" placeholder="" id="id1">
<option value="1">Pass</option>
<option value="0">Fail</option>
</select><i></i>
</label>
<label class="select ">
<select class="form-control" name="selecname" placeholder="" id="id1">
<option value="1">Pass</option>
<option value="0">Fail</option>
</select><i></i>
</label>
<label class="select ">
<select class="form-control" name="selecname" placeholder="" id="id1">
<option value="1">Pass</option>
<option value="0">Fail</option>
</select><i></i>
</label>
<label class="select ">
<select class="form-control" name="selecname" placeholder="" id="id1">
<option value="1">Pass</option>
<option value="0">Fail</option>
</select><i></i>
</label>
<label class="select ">
<select class="form-control" name="selecname" placeholder="" id="id1">
<option value="1">Pass</option>
<option value="0">Fail</option>
</select><i></i>
</label>
<label class="select ">
<select class="form-control" name="selecname" placeholder="" id="id1">
<option value="1">Pass</option>
<option value="0">Fail</option>
</select><i></i>
</label>
<label class="select ">
<select class="form-control" name="selecname" placeholder="" id="id1">
<option value="1">Pass</option>
<option value="0">Fail</option>
</select><i></i>
</label>
<label class="select ">
<select class="form-control" name="selecname" placeholder="" id="id1">
<option value="1">Pass</option>
<option value="0">Fail</option>
</select><i></i>
</label>
<label class="select ">
<select class="form-control" name="selecname" placeholder="" id="id1">
<option value="1">Pass</option>
<option value="0">Fail</option>
</select><i></i>
</label>
<label class="select ">
<select class="form-control" name="selecname" placeholder="" id="id1">
<option value="1">Pass</option>
<option value="0">Fail</option>
</select><i></i>
</label>
的链接
答案 0 :(得分:1)
您可以尝试这样: 的 DEMO 强>
<强> CSS:强>
div {
width:600px;
height:60px;
display:block;
white-space:nowrap;
overflow:auto;
}
input {
height:26px;
margin-right:5px;
border:1px solid;
}
<强> HTML:强>
<div>
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
</div>
答案 1 :(得分:0)
尝试将overflow:auto
用于父级。
答案 2 :(得分:0)
只需使用
overflow-x: scroll;
我认为有效
答案 3 :(得分:0)
首先,在.addContainer中创建一个div。
<div class="addContainer">
<div class='wrapper'>
<label class="select ">
<select class="form-control" name="selecname" placeholder="" id="id1">
<option value="1">Pass</option>
<option value="0">Fail</option>
</select><i></i>
</label>
<label class="select ">
<select class="form-control" name="selecname" placeholder="" id="id1">
<option value="1">Pass</option>
<option value="0">Fail</option>
</select><i></i>
</label>
<label class="select ">
<select class="form-control" name="selecname" placeholder="" id="id1">
<option value="1">Pass</option>
<option value="0">Fail</option>
</select><i></i>
</label>
<label class="select ">
<select class="form-control" name="selecname" placeholder="" id="id1">
<option value="1">Pass</option>
<option value="0">Fail</option>
</select><i></i>
</label>
<label class="select ">
<select class="form-control" name="selecname" placeholder="" id="id1">
<option value="1">Pass</option>
<option value="0">Fail</option>
</select><i></i>
</label>
<label class="select ">
<select class="form-control" name="selecname" placeholder="" id="id1">
<option value="1">Pass</option>
<option value="0">Fail</option>
</select><i></i>
</label>
<label class="select ">
<select class="form-control" name="selecname" placeholder="" id="id1">
<option value="1">Pass</option>
<option value="0">Fail</option>
</select><i></i>
</label>
<label class="select ">
<select class="form-control" name="selecname" placeholder="" id="id1">
<option value="1">Pass</option>
<option value="0">Fail</option>
</select><i></i>
</label>
<label class="select ">
<select class="form-control" name="selecname" placeholder="" id="id1">
<option value="1">Pass</option>
<option value="0">Fail</option>
</select><i></i>
</label>
<label class="select ">
<select class="form-control" name="selecname" placeholder="" id="id1">
<option value="1">Pass</option>
<option value="0">Fail</option>
</select><i></i>
</label>
<label class="select ">
<select class="form-control" name="selecname" placeholder="" id="id1">
<option value="1">Pass</option>
<option value="0">Fail</option>
</select><i></i>
</label>
<label class="select ">
<select class="form-control" name="selecname" placeholder="" id="id1">
<option value="1">Pass</option>
<option value="0">Fail</option>
</select><i></i>
</label>
<label class="select ">
<select class="form-control" name="selecname" placeholder="" id="id1">
<option value="1">Pass</option>
<option value="0">Fail</option>
</select><i></i>
</label>
</div>
</div>
然后应用以下CSS:
.addContainer {
overflow: scroll; width: 500px;
}
并给包装器div一个非常大的宽度:
.wrapper {
width: 1000px;
}
如果你可以使用JQuery,那么你可以像这样动态创建.wrapper的宽度:
$(document).ready(function() {
var container_width = 65 * $(".wrapper label").length;
$(".wrapper").css("width", container_width);
});
将65更改为标签的宽度(我假设每个标签的宽度为65)