问题是一个div向下移动一个向上,为什么? 我做了两个双div,包括内联块和浮动到右边,每个块内部相同。 我尝试了许多改变,没有任何解决方案。
.lawyer-online {
display: inline-block;
width: 200px;
height: 100px;
margin: 10px;
}
.lawyer-avatar {
display: inline-block;
height: 100px;
width: 100px;
float:right;
}
.lawyer-avatar-relative {
position: relative;
}
.lawyer-name-box{
position: absolute;
bottom: 0em;
right: 0em;
width: 100%;
height: 2em;
background: rgba(25, 126, 215, 0.9);
color: #fff;
}
.lawyer-name-box span{
padding: 10px 10px 10px 0;
}
.lawyer_description {
background: rgba(25, 126, 215, 0.5);
height: 100px;
width: 100px;
display: inline-block;
clear: right;
}
<div id="lawyer-1" class="lawyer-online">
<div class="lawyer-avatar">
<div class="lawyer-avatar-relative">
<img src="http://wdd.co.il/wp-content/uploads/2015/08/angry-judge-100x100.jpg">
<div class="lawyer-name-box">
<span>name name</span>
</div>
</div>
</div>
<div class="lawyer_description">short text</div>
</div>
<div id="lawyer-2" class="lawyer-online">
<div class="lawyer-avatar">
<div class="lawyer-avatar-relative">
<img src="http://wdd.co.il/wp-content/uploads/2015/08/angry-judge-100x100.jpg">
<div class="lawyer-name-box">
<span>name name</span>
</div>
</div>
</div>
<div class="lawyer_description">long text long text long text</div>
</div>
问题是一个div向下移动一个向上,为什么? 我做了两个双div,包括内联块和浮动到右边,每个块内部相同。 我尝试了许多改变,没有任何解决方案。
答案 0 :(得分:3)
您应在vertical-align: top
课程中添加.lawyer-online
。
.lawyer-online {
display: inline-block;
width: 200px;
height: 100px;
margin: 10px;
vertical-align: top;
}
答案 1 :(得分:2)
出现这种情况是因为inline-block
默认收到vertical-align: baseline
,并不总是以所需的方式对齐元素。
您可以通过在vertical-align: top
的声明块中明确指定.lawyer-online
来解决此问题。 (或者中间/底部,它们也可以作为值。)
.lawyer-online {
display: inline-block;
width: 200px;
height: 100px;
margin: 10px;
vertical-align: top;
}
.lawyer-avatar {
display: inline-block;
height: 100px;
width: 100px;
float:right;
}
.lawyer-avatar-relative {
position: relative;
}
.lawyer-name-box{
position: absolute;
bottom: 0em;
right: 0em;
width: 100%;
height: 2em;
background: rgba(25, 126, 215, 0.9);
color: #fff;
}
.lawyer-name-box span{
padding: 10px 10px 10px 0;
}
.lawyer_description {
background: rgba(25, 126, 215, 0.5);
height: 100px;
width: 100px;
display: inline-block;
clear: right;
}
&#13;
<div id="lawyer-1" class="lawyer-online">
<div class="lawyer-avatar">
<div class="lawyer-avatar-relative">
<img src="http://wdd.co.il/wp-content/uploads/2015/08/angry-judge-100x100.jpg">
<div class="lawyer-name-box">
<span>name name</span>
</div>
</div>
</div>
<div class="lawyer_description">short text</div>
</div>
<div id="lawyer-2" class="lawyer-online">
<div class="lawyer-avatar">
<div class="lawyer-avatar-relative">
<img src="http://wdd.co.il/wp-content/uploads/2015/08/angry-judge-100x100.jpg">
<div class="lawyer-name-box">
<span>name name</span>
</div>
</div>
</div>
<div class="lawyer_description">long text long text long text</div>
</div>
&#13;
答案 2 :(得分:1)
您需要添加vertical-align:top
.lawyer-online {
display: inline-block;
width: 200px;
height: 100px;
margin: 10px;
vertical-align:top;
}