我有一个非常简单的示例,其中外部 DIV 未根据内容完全调整大小。问题是内部 DIV 的顶级属性,这使得它从父级中滑出。有没有办法垂直调整外部 DIV 的大小,无论是否使用 top 属性?我知道我可以为此使用 jQuery,但是否可以仅使用 CSS?
<div id="divPTX_01" style="position:relative;min-height:1px;overflow:hidden;min-width:1px; border: 1px solid red;">
<div style="position:relative;float:left;border:2px solid blue;top:130px;">
<span>Test</span><br/>
<span>Test</span><br/>
<span>Test</span><br/>
<span>Test 6</span><br/>
<span>Test 7</span><br/>
<span>Test</span><br/>
<span>Test</span><br/>
<span>Test</span><br/>
<span>Test 6</span><br/>
<span>Test 7</span><br/>
</div>
</div>
最佳答案
尝试使用 margin-top 而不是 top
<div id="divPTX_01" style="position:relative;min-height:1px;overflow:hidden;min-width:1px; border: 1px solid red;">
<div style="position:relative;float:left;border:2px solid blue;margin-top:130px">
<span>Test</span><br/>
<span>Test</span><br/>
<span>Test</span><br/>
<span>Test 6</span><br/>
<span>Test 7</span><br/>
<span>Test</span><br/>
<span>Test</span><br/>
<span>Test</span><br/>
<span>Test 6</span><br/>
<span>Test 7</span><br/>
</div>
</div>
关于html - 当在内部 DIV 上使用 top 属性时,父 DIV 垂直调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46094869/