简体   繁体   English

当选择是行中的最后一项时,浮动Divs无法正确换行

[英]Floated Divs not wrapping correctly when select is last item on line

I am floating divs that contain either a textbox or select element. 我浮动包含文本框或选择元素的div。 I want the divs to wrap to the next line when it runs out of space. 我希望div在空间不足时换行到下一行。 This works fine when the last element of the line is a text box, but not when its a select. 当该行的最后一个元素是文本框时,此方法工作正常,但当其为select时则不能。 You can resize your browser to see the result. 您可以调整浏览器的大小以查看结果。

example html: 示例html:

<div style="display:block;float:left;padding-right:5px;vertical-align:bottom;padding-bottom:2px;">
  <span>Text1</span>
  <br>
  <input id="TextBox" type="text" tabindex="-1" size="3" value="1">
</div>    

JS Fiddle: http://jsfiddle.net/NsxJM/ JS小提琴: http//jsfiddle.net/NsxJM/

预期行为

意外行为

If you are open to suggestions you can do this with display: inline property. 如果您愿意接受建议,则可以使用display:inline属性来完成。

FIDDLE 小提琴

Eg HTML 例如HTML

<div class="wrapper">
  <label for="one">Text</label><br/>
  <input id="one" type="text" value="1" />
</div>

<div class="wrapper">
  <label for="tow">Text</label><br/>
  <input id="two" type="text" value="2" />
</div>
<div class="wrapper">
  <label for="three">Text</label><br/>
  <input id="three" type="text" value="3" />
</div>

<div class="wrapper">
  <label for="four">Text</label><br/>
  <input id="four" type="text" value="4" />
</div>

<div class="wrapper">
  <label for="five">Text</label><br/>
  <input id="five" type="text" value="5" />
</div>

<div class="wrapper">
  <label for="sel">*Select</label><br/>
  <select id="sel">
    <option>--Select--</option>
    <option>1</option>
    <option>2</option>
  </select>
</div>

<div class="wrapper">
  <label for="six">Text</label><br/>
  <input id="six" type="text" value="6" />
</div>

<div class="wrapper">
  <label for="seven">Text</label><br/>
  <input id="seven" type="text" value="7" />
</div>

Eg CSS 例如CSS

.wrapper{
  display: inline-block;
  *display: inline;
  zoom: 1;
}

  input[type='text']{
  width: 50px;
}

The problem is with the height of the div that contains the <select> 问题在于包含<select>div的高度

All the divs with text boxes has height 46px but the one with select list has height 44px. 所有带文本框的div高度为46px,而带有选择列表的div高度为44px。 If you assign it 46px height inline, the issue will be resolved. 如果您将其内联分配为46px的高度,则此问题将得到解决。

See working fiddle 查看工作提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM