简体   繁体   English

将div置于另一个div下

[英]Position div under another div

I have 2 divs: div with submit and order-content div 我有2个div:具有提交和订单内容div的div

  <div class="order"> <form> <div class="input">submit</div> </form> <div class="order-content"> <table><tr><td></td></tr></table> <div class="new-product"> <div class="product-add"> <form> </form> </div> </div> </div> </div> 

Also when I add new product, im appending new table row, so css position attribute doesn't work as I want cause it has static values. 另外,当我添加新产品时,我会追加新表格行,因此css position属性无法正常运行,因为它具有静态值。 I thought about making jquery which gets height of new row and increments submit input position, but is there better solution? 我考虑过让jquery获得新行的高度并递增提交输入位置,但是有更好的解决方案吗?

You need to use JavaScript to move elements in DOM to a different order than they appear in the original document. 您需要使用JavaScript将DOM中的元素移动到与原始文档中出现的元素不同的顺序。 Something like (jsfiddle with jQuery): 像(与jQuery的jsfiddle)类似:

https://jsfiddle.net/khabgc6h/2/ https://jsfiddle.net/khabgc6h/2/

$('.input').insertAfter('.new-product')

 $(".input").click(function(){ $("#table").append('<tr><td>Data</td></tr>') }); 
 <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <div class="order"> <div class="col-xs-12 form-group"> </div> <div class="col-xs-12 form-group"> <button class="btn input"> submit </button></div> <div class="col-xs-12 order-content"> <table id="table" class="form-group"><tr><td>Data</td></tr></table> <div class="new-product"> <div class="product-add"> <form> <input type="text" class="form-control" /> </form> </div> </div> </div> </div> 

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

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