Html 与内联块未对齐(其他元素被推下)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8120466/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Missalignment with inline-block (other elements pushed down)
提问by simon
I'm trying to align small boxes in a row. These boxes have something like 2 elements in each. In some cases, the first element is so "much" text, that it splits into 2 lines. If this happens, all other blocks in this special line are shown below.
我正在尝试将小框对齐。这些盒子每个都有 2 个元素。在某些情况下,第一个元素是“太多”文本,它分成 2 行。如果发生这种情况,此特殊行中的所有其他块如下所示。
Long story short, here is the example: http://jsfiddle.net/PMRQ5/
长话短说,这里是例子:http: //jsfiddle.net/PMRQ5/
If you resize the HTML field, you can see what I mean. Can somebody help?
如果您调整 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>
回答by JNDPNT
Add vertical-align: top
or vertical-align: bottom
to the box, depends on what you want.
添加vertical-align: top
或vertical-align: bottom
到框中,取决于您想要什么。
回答by Ani Menon
.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>