这是我的代码:
#wrapper {
margin: 0 auto;
display: block;
width: 1200px;
border: 1px solid red;
}
div {
width: 150px;
height: 200px;
border: 1px solid red;
display: inline-block;
margin-right: 80px;
}

<div id="wrapper">
<div>this is test. this is test.</div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
&#13;
答案 0 :(得分:2)
始终记得为vertical-align
元素定义inline-block
。
#wrapper {
margin: 0 auto;
display: block;
width: 1200px;
border: 1px solid red;
}
div {
width: 150px;
height: 200px;
border: 1px solid red;
display: inline-block;
vertical-align: top; /* add this always with inline-block */
margin-right: 80px;
}
<div id="wrapper">
<div>thisd ihd sofjdlkfj dlkfjdlkfj d</div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
答案 1 :(得分:1)
显示为inline-block
的元素与其父基线对齐,因此当它具有内容时向下移动。
给他们一个vertical-align: top
值将解决这个问题。
另一种选择是删除内联块并提供wrapper
display: flex
#wrapper {
margin: 0 auto;
display: flex;
width: 1200px;
border: 1px solid red;
}
div {
width: 150px;
height: 200px;
border: 1px solid red;
margin-right: 80px;
}
<div id="wrapper">
<div>this is test. this is test.</div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
答案 2 :(得分:0)
将vertical-align: top;
添加到您的div的css; D