2013-03-11 143 views
4

我有一个文章标签,内部生成wordpress的文章的php代码。它们并不完全相同,它取决于内容。他们按浮动两列组织。对齐浮动div顶部到底部

如果第一行中的文章与同一行中的另一篇文章的高度不同,第二行将与biger div的底部对齐。现在我想对齐它们而没有任何间距。

下面是一些CSS:

#container { 
width: 1000px; 
margin: 0px auto; 
} 

article { 
position: relative; 
width: 435px; 
margin: 10px 10px; 
background-color: rgba(0, 0, 0, 0.5); 
padding: 20px; 
float: left; 
} 

编辑的jsfiddle(现在的内容来演示该问题):http://jsfiddle.net/4PMj5/6/

+0

删除'margin:10px 10px;'? – Morpheus 2013-03-11 11:35:18

+0

这里的文章是类还是id? – Mihir 2013-03-11 11:35:22

+2

@Mihir html5标签 – Morpheus 2013-03-11 11:35:51

回答

1

您可以使用evenodd孩子伪选择在你的CSS。

article:nth-child(even) { 
    position: relative; 
    width: 435px; 
    margin: 10px 10px; 
    background-color: rgba(0, 0, 0, 0.5); 
    padding: 20px; 
    float: right; 
} 
article:nth-child(odd) { 
    position: relative; 
    width: 435px; 
    margin: 10px 10px; 
    background-color: rgba(0, 0, 0, 0.5); 
    padding: 20px; 
    float: left; 
} 

结果如下:this updated fiddle