元素中心内容应该根据其子元素调整其高度,但是如果我在其某个子元素上使用了float:left
,例如元素leftContent,leftContent将在其中心内容之外包含95%的身体。由于中心内容高度不会调整以保持其内部的左内容。如果子元素包含浮动元素,则父div无法识别子元素的高度:left
如果我从leftContent中删除float:left
,元素center-content将调整它的高度以维护leftContent元素。为什么float:left
会这样做?
为了简化,我想让两个小盒子在一个大盒子里留下另一个浮子。这个大盒子应该相应地改变其高度。
HTML
#header, #footer, #content-wapper, section {
max-width: 100%;
margin: 0 auto;
text-align: center;
}
#leftContent{
display: inline-block;
width: 49%;
height: auto;
float: left;
}
input{
width: 98%;
height: 40px;
border: solid 1px gray;
background-color: white;
}
.center-content {
width: 960px;
max-width: 100%;
margin: 0 auto;
padding: 2vw 0 2vw 0;
background-color: #E8E8E8
}
<section class="center-content">
<div id="leftContent">
<a><input name="income" type="text" id="income0" placeholder="Main Applicant Annual Income"></a><br>
<a><input name="income" type="text" id="income1" placeholder="Main Applicant Any-other Income"></a><br>
<a><input name="income" type="text" id="income2" placeholder="Second Applicant Annual Income"></a><br>
<a><input name="income" type="text" id="income3" placeholder="Second Applicant Any-other Income"></a><br><br>
<a><button class="btnCal" onclick="calculateMort()">Calculator</button></a>
</div>
</section>
为什么不只是删除浮动?无论如何,你已经制作了内嵌块 – Pete
我只是为了测试目的而做的。但我想让它向左飘荡。因为它不能保证在右边会有任何东西。 – Luke
但是如果你有显示内联块你的左边和右边将并排︰https://jsfiddle.net/q93wpqpd/ – Pete