内联块未对齐(其他元素被压下)

时间:2011-11-14 10:48:38

标签: html css row offset

我正在尝试连续排列小方块。这些盒子各有两个元素。在某些情况下,第一个元素是如此“多”的文本,它分成2行。如果发生这种情况,此特殊行中的所有其他块如下所示。

长话短说,这是一个例子: http://jsfiddle.net/PMRQ5/

如果你调整HTML字段的大小,你可以看到我的意思。有人可以帮忙吗?

.songlist .even {
  background: #c2e4fa;
  background: -moz-linear-gradient(top, #d9eefc, #c2e4fa);
  margin-right: 5px;
}
.songlist .odd {
  background: #faf4c2;
  background: -moz-linear-gradient(top, #fcf8d9, #faf4c2);
  margin-right: 5px;
}
.songlist .itemBox {
  font-size: 11px;
  width: 220px;
  min-height: 100px;
  clear: both;
  padding: 5px;
  margin: 5px 10px 5px 10px;
  display: inline-block;
  position: relative;
  border-radius: 4px;
}
.songlist .itemBox .title {
  font-weight: bold;
  font-size: 16px;
}
.songlist .itemBox .artist {
  clear: left;
  font-size: 11px;
}
.songlist .itemBox .titlerating {
  bottom: 10px;
  left: 10px;
  position: absolute;
}
.songlist .itemBox .dance {
  bottom: 5px;
  right: 10px;
  position: absolute;
}
<div class='songlist'>
  <div class='itemBox even'>
    <div class='cover'></div>
    <div class='title'>You and you</div>
    <div class='artist'>101 Strings Orchestra</div>
    <div class='clear'></div>
  </div>
  <div class='itemBox odd'>
    <div class='title'>The Queen's lace hankerchief waltz</div>
    <div class='artist'>101 Strings Orchestra</div>
    <div class='clear'></div>
  </div>
  <div class='itemBox even'>
    <div class='cover'></div>
    <div class='title'>Voices of spring</div>
    <div class='artist'>101 Strings Orchestra</div>
    <div class='clear'></div>
  </div>
  <div class='itemBox odd'>
    <div class='cover'></div>
    <div class='title'>Roses from the south</div>
    <div class='artist'>101 Strings Orchestra</div>
    <div class='clear'></div>
  </div>
</div>

2 个答案:

答案 0 :(得分:120)

http://jsfiddle.net/PMRQ5/1/

在框中添加vertical-align: topvertical-align: bottom,具体取决于您的需求。

答案 1 :(得分:1)

.songlist .even {
  background:#c2e4fa;
  background:-moz-linear-gradient(top,#d9eefc,#c2e4fa);
  margin-right:5px;
}
.songlist .odd {
  background:#faf4c2;
  background:-moz-linear-gradient(top,#fcf8d9,#faf4c2);
  margin-right:5px;
}
.songlist .itemBox {
  font-size:11px;
  width:220px;
  min-height:100px;
  clear:both;
  padding:5px;
  margin:5px 10px 5px 10px;
  display:inline-block;
  position:relative;
  border-radius:4px;
  vertical-align: bottom;
}
.songlist .itemBox .title {
  font-weight:bold;
  font-size:16px;
}
.songlist .itemBox .artist {
  clear:left;
  font-size:11px;
}
.songlist .itemBox .titlerating {
  bottom:10px;
  left:10px;
  position:absolute;
}
.songlist .itemBox .dance {
  bottom:5px;
  right:10px;
  position:absolute;
}
<div class='songlist'>
    <div class='itemBox even'>
        <div class='cover'></div>        
        <div class='title'>You and you</div>
        <div class='artist'>101 Strings Orchestra</div>        
        <div class='clear'></div>
    </div>                    
    <div class='itemBox odd'>    
        <div class='title'>The Queen's lace hankerchief waltz</div>
        <div class='artist'>101 Strings Orchestra</div>        
        <div class='clear'></div>
    </div>
    <div class='itemBox even'>
        <div class='cover'></div>    
        <div class='title'>Voices of spring</div>
        <div class='artist'>101 Strings Orchestra</div>    
        <div class='clear'></div>
    </div>                    
    <div class='itemBox odd'>
        <div class='cover'></div>        
        <div class='title'>Roses from the south</div>
        <div class='artist'>101 Strings Orchestra</div>    
    <div class='clear'></div>
    </div>
</div>