我有两个div没有嵌套,一个在另一个之下。它们都在一个父div中,并且此父div重复。所以基本上:
<div id='parent_div_1'> <div class ='child_div_1'></div> <div class ='child_div_2'></div> </div> <div id='parent_div_2'> <div class ='child_div_1'></div> <div class ='child_div_2'></div> </div> <div id='parent_div_3'> <div class ='child_div_1'></div> <div class ='child_div_2'></div> </div>
我想获得每对child_div_1和child_div_2彼此相邻。我如何做到这一点?
解决方法
#parent_div_1,#parent_div_2,#parent_div_3 { width: 100px; height: 100px; border: 1px solid red; margin-right: 10px; float: left; } .child_div_1 { float: left; margin-right: 5px; }
检查工作示例在http://jsfiddle.net/c6242/1/